Database Reference
In-Depth Information
// set up tuple descriptor for result info
get_call_result_type(fcinfo, &resultTypeId,
&resultTupleDesc);
// check that SQL function definition is
set up to return arecord
Assert(resultTypeId == TYPEFUNC_COMPOSITE);
// make the tuple descriptor known to
postgres as valid return type
BlessTupleDesc(resultTupleDesc);
retvals[0] = Int32GetDatum(c);
retvals[1] = Int32GetDatum(b);
retvals[2] = Int32GetDatum(a);
retvals[3] =
Int32GetDatum(retvals[0]*retvals[1]+retvals[2]);
retnulls[0] = aisnull;
retnulls[1] = bisnull;
retnulls[2] = cisnull;
retnulls[3] = aisnull || bisnull ||
cisnull;
rettuple = heap_form_tuple(
resultTupleDesc, retvals, retnulls );
PG_RETURN_DATUM( HeapTupleGetDatum(
rettuple ) );
}
Extracting fields from an argument tuple
Getting the fields of an argument tuple is easy. First, you fetch the
HeapTupleHeader file of the argument into the th variable using the
PG_GETARG_HEAPTUPLEHEADER(0) macro, and then for each field you get the
Datum (a generic type which can hold any field value in PostgreSQL) by the field
name using the GetAttributeByName() function and then assign its value to a
local variable after converting it to int32 via DatumGetInt32() .
Search WWH ::




Custom Search