Re: C-Function: Returning Rows

From: Carel Combrink <s25291930(at)tuks(dot)co(dot)za>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL Novice List <pgsql-novice(at)postgresql(dot)org>
Subject: Re: C-Function: Returning Rows
Date: 2010-05-10 15:49:34
Message-ID: 20100510174934.qnjkezyqckooow8o@student.up.ac.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Quoting Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

> Carel Combrink <s25291930(at)tuks(dot)co(dot)za> writes:
>> in my function I have the following:
>> TupleDesc tup_descriptor;
>> Datum dat_values[2];
>> HeapTuple heap_tuple;
>> bool *pNulls;
>
>> get_call_result_type(fcinfo, NULL, &tup_descriptor);
>> BlessTupleDesc(tup_descriptor);
>> dat_values[0] = Int32GetDatum(50);
>> dat_values[1] = Int32GetDatum(20);
>> iTup_Length = tup_descriptor->natts;
>> pNulls = palloc(iTup_Length * sizeof(bool));
>> heap_tuple = heap_form_tuple(tup_descriptor, dat_values, pNulls);
>> PG_RETURN_DATUM(HeapTupleGetDatum(heap_tuple));
>
>> Am I doing something wrong in my function that would have this affect?
>
> Failing to initialize the values of pNulls[], no doubt.
>
> It would also be a good idea to check for a failure result from
> get_call_result_type.
>
> BTW, what's the rationale for using a fixed-length Datum array and
> a variable-length nulls array? Usually people handle both of those
> the same way.
>
> regards, tom lane
>

I've added a line to initialize the values like follow:

malloc(pNulls, false, iTup_Length * sizeof(bool));

and it works perfectly each time.

As for checking the failure result: I did not put it in my email but
actually I am checking to see if it is not "TYPEFUNC_COMPOSITE".

I did use a fixed-length nulls array but somewhere in my
testing/frustration I mixed the two (I played with various options).

I noted, if using fixed-length nulls array I should set the array to
false also otherwise the same is experienced. Is this supposed to
happen this way? Is there documentation on this, I tried googling the
function with no success?

Thank you Tom,
--
Carel Combrink
s25291930(at)tuks(dot)co(dot)za

This message and attachments are subject to a disclaimer. Please refer
to www.it.up.ac.za/documentation/governance/disclaimer/ for full
details. / Hierdie boodskap en aanhangsels is aan 'n vrywaringsklousule
onderhewig. Volledige besonderhede is by
www.it.up.ac.za/documentation/governance/disclaimer/ beskikbaar.

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2010-05-10 16:44:56 Re: C-Function: Returning Rows
Previous Message Tom Lane 2010-05-10 14:38:49 Re: C-Function: Returning Rows