C-Function: Returning Rows

From: Carel Combrink <s25291930(at)tuks(dot)co(dot)za>
To: PostgreSQL Novice List <pgsql-novice(at)postgresql(dot)org>
Subject: C-Function: Returning Rows
Date: 2010-05-10 10:12:17
Message-ID: 20100510121217.e7gk1kzbnkwwoc0w@student.up.ac.za
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

hi,

I have a C Function that returns a row. The following was used to
create the function (some code omitted):

CREATE TYPE __Result AS (status integer, last_response integer);
CREATE OR REPLACE FUNCTION my_function(...) RETURNS __Result ...

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));

Calling the function works as expected but the return values (row) is
not correct, there is some problems. Sometimes when I call the
function I get:
my_function
--------------
(50,20)
(1 row)

and other times I get:
my_function
--------------
(,)
(1 row)

and I have seen:
my_function
--------------
(50,)
(1 row)

Am I doing something wrong in my function that would have this affect?

I do not want to return the hard coded values but rather variables in
my function, this is for testing.

PostgreSQL 8.4 on Ubuntu 10.04
--
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.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2010-05-10 14:38:49 Re: C-Function: Returning Rows
Previous Message Didier Gasser-Morlay 2010-05-08 15:54:21 Re: field names for new in trigger function