Database Reference
In-Depth Information
(c,b,a,x=c*b+a)
, and then expand it to return set of permutations such as the
sample
pl/pythonu
function.
Returning a single tuple of a complex type
The first step in constructing a version of the reverse permutations function in C is to
start with simply being able to return a single record of type
abc
.
Datum
c_reverse_tuple(PG_FUNCTION_ARGS)
{
HeapTupleHeader
th;
int32 a,b,c;
bool aisnull, bisnull, cisnull;
TupleDesc
resultTupleDesc;
Oid
resultTypeId;
Datum
retvals[4];
bool retnulls[4];
HeapTuple
rettuple;
// get the tuple header of 1st argument
th =
PG_GETARG_HEAPTUPLEHEADER(0);
// get argument Datum's and convert them to
int32
a =
DatumGetInt32(GetAttributeByName
(th,
"a", &aisnull));
b = DatumGetInt32(GetAttributeByName(th,
"b", &bisnull));
c = DatumGetInt32(GetAttributeByName(th,
"c", &cisnull));
// debug: report the extracted field values
ereport(INFO,
(errmsg("arg: (a: %d,b: %d, c:
%d)", a, b, c)) );