C-Function: Returning Rows

Поиск
Список
Период
Сортировка
От Carel Combrink
Тема C-Function: Returning Rows
Дата
Msg-id 20100510121217.e7gk1kzbnkwwoc0w@student.up.ac.za
обсуждение исходный текст
Ответы Re: C-Function: Returning Rows  (Tom Lane <tgl@sss.pgh.pa.us>)
Список 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@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 по дате отправления:

Предыдущее
От: Didier Gasser-Morlay
Дата:
Сообщение: Re: field names for new in trigger function
Следующее
От: Tom Lane
Дата:
Сообщение: Re: C-Function: Returning Rows