Re: C-Function: Returning Rows - Mailing list pgsql-novice

From Carel Combrink
Subject Re: C-Function: Returning Rows
Date
Msg-id 20100510174934.qnjkezyqckooow8o@student.up.ac.za
Whole thread Raw
In response to Re: C-Function: Returning Rows  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: C-Function: Returning Rows  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
Quoting Tom Lane <tgl@sss.pgh.pa.us>:

> Carel Combrink <s25291930@tuks.co.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@tuks.co.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.



pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: C-Function: Returning Rows
Next
From: Tom Lane
Date:
Subject: Re: C-Function: Returning Rows