Perhaps the RECORD stuff would help you? It's poorly documented, but you could look at the code for SRFs to see how to use it.
regards, tom lane
Ok, RECORD was a keyword, thank you. But I have questions: 1 What do you mean SRF? Set Return Function? 2 Some example I found in contrib/tablefunc, and so I create test function: Datum qqn(PG_FUNCTION_ARGS) { int attnum = PG_NARGS(); TupleDesc tupdesc; char attname[NAMEDATALEN]; int i; TupleTableSlot *slot; AttInMetadata *attinmeta; Datum *dvalues, result; char *nulls; HeapTuple tuple;
/* set tupledesc */ tupdesc = CreateTemplateTupleDesc(attnum, false); for (i = 0; i < attnum; i++) { sprintf(attname, "z%d", i+1); TupleDescInitEntry(tupdesc, i+1, attname, INT4OID, -1, 0, false); }
slot = TupleDescGetSlot(tupdesc);
attinmeta = TupleDescGetAttInMetadata(tupdesc);
dvalues = (Datum *) palloc(attnum * sizeof(Datum)); nulls = (char *) palloc(attnum * sizeof(char));
for (i = 0; i < attnum; i++) { nulls[i] = ' '; dvalues[i] = PG_GETARG_DATUM(i); }
/* tupdesc = attinmeta->tupdesc */ tuple = heap_formtuple(tupdesc, dvalues, nulls); pfree(dvalues); pfree(nulls); result = TupleGetDatum(slot, tuple);
PG_RETURN_DATUM(result); }
create function qqN(int4) returns record AS 'MODULE_PATHNAME' LANGUAGE 'C';
create function qqN(int4,int4) returns record AS 'MODULE_PATHNAME' LANGUAGE 'C';
# select * from qqn(1) as c(qq int4); qq ---- 1 (1 row)
# select * from qqn(1,2) as c(qq int4, qq1 int4); qq | qq1 ----+----- 1 | 2 (1 row)
It works fine. But is there way not to point 'as c(qq int4, qq1 int4)'? Notice: qqn isn't real, it's test only.
Thank you.
-- Teodor Sigaev E-mail: [EMAIL PROTECTED]
---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly