Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice

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

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:
(1 row)

and other times I get:
(1 row)

and I have seen:
(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

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


pgsql-novice by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group