Re: Function returns composite type

From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Joe Conway <mail(at)joeconway(dot)com>
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 16:26:01
Message-ID: 3EE75819.9090608@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> 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>
Thank you for point.

>
> 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.
Ok, I see

>
> 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.

Can we make follow:
Functions, returning record and called in sql without description,
??lled with specific arguments (as is done for SRF by SRF_IS_FIRSTCALL()). With
this arguments it should return TupleDesc.
As I see, the place to such call is addRangeTableEntryForFunction at
src/parser/parse_relation.c near lines N921-964. In this place we have all that
we need.

Am I wrong?

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-06-11 16:37:46 Re: Function returns composite type
Previous Message Bruce Momjian 2003-06-11 16:24:17 Re: [HACKERS] SAP and MySQL ... [and Benchmark]