Database Reference
In-Depth Information
struct c_reverse_tuple_args* args;
if( SRF_IS_FIRSTCALL() )
{
HeapTupleHeader th =
PG_GETARG_HEAPTUPLEHEADER(0);
MemoryContext oldcontext;
/* create a function context for
cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT() ;
/* switch to memory context appropriate
for multiple function calls */
oldcontext = MemoryContextSwitchTo(
funcctx->multi_call_memory_ctx
);
/* allocate and zero-fill struct for
persisting extracted arguments*/
args = palloc0(sizeof(struct
c_reverse_tuple_args));
args->anyargnull = false;
funcctx->user_fctx = args;
/* total number of tuples to be
returned */
funcctx->max_calls = 6; // there are 6
permutations of 3 elements
// extract argument values and
NULL-ness
for(i=0;i<3;i++){
args->argvals[i] =
DatumGetInt32(GetAttributeByName(th,
argnames[i], &(args->argnulls[i])));
if (args->argnulls[i])
args->anyargnull = true;
}
// set up tuple for result info
if (get_call_result_type(fcinfo, NULL,
Search WWH ::




Custom Search