Re: Function returns composite type

From: Joe Conway <mail(at)joeconway(dot)com>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Function returns composite type
Date: 2003-06-11 15:39:07
Message-ID: 3EE74D1B.6070909@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Teodor Sigaev wrote:
> it's a great pity :(.
>
> But in function I already make 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);
> }
> As I understand, this code makes full description of returning value,
> including types and column's names.
> Is this info used anywhere?

You could actually get the tupdesc from the caller if you wanted. See,
for example crosstab_hash() in contrib/tablefunc:

<snip>
/* check to see if caller supports us returning a tuplestore */
if (!rsinfo || !(rsinfo->allowedModes & SFRM_Materialize))
elog(ERROR, "crosstab: materialize mode required, but it is not "
"allowed in this context");

per_query_ctx = rsinfo->econtext->ecxt_per_query_memory;
oldcontext = MemoryContextSwitchTo(per_query_ctx);

/* get the requested return tuple description */
tupdesc = CreateTupleDescCopy(rsinfo->expectedDesc);
</snip>

The problem is that the parser needs the column data types long before
your function gets called by the executor. Therefore you either need the
predetermined return type, or the query string definition.

We've discussed a couple of times allowing the parser to "interrogate"
the function at parse time to let it determine what the runtime tupdesc
will be, but I haven't been able to come up with a good way to do that.

Joe

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hans-Jürgen Schönig 2003-06-11 15:40:45 Pre-allocation of shared memory ...
Previous Message pgsql 2003-06-11 15:21:37 Re: SELECT TAKES A LOOOONG TIME