Skip site navigation (1) Skip section navigation (2)

Re: [Fwd: SETOF input parameters (was Re: [HACKERS] proposal:

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Subject: Re: [Fwd: SETOF input parameters (was Re: [HACKERS] proposal:
Date: 2002-12-30 01:50:09
Message-ID: 14505.1041213009@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-hackerspgsql-patches
Joe Conway <mail(at)joeconway(dot)com> writes:
> Tom Lane wrote:
>> Implement what exactly?

> Well, I want to allow a single table function (or srf if you prefer) in the 
> target list as discussed above.

> Currently, when you try it, record_out() gets called from printtup() when the
> srf is encountered, which generates an ERROR.

Oh, you're thinking about the multi-column aspect of it, not the
multi-row aspect.  You really ought to keep those strictly separate;
their design and implementation problems are quite different IMHO.
I find it quite confusing to refer to both cases as "SRFs".

I think there once was support for multi-column function results in
SELECT; at least that's the best understanding I can muster of the old
"fjoin" code.  But that's been broken since the Postgres95 SQL rewrite
(if not earlier), and I finally ripped out the last shreds of it just a
couple weeks ago.  I don't think it could have been revived short of a
complete rewrite anyway, so I'm not shedding a tear.  You could look at
old releases to see how it worked, though you might have to go back to
Postgres 4.2 or even before to find something that "worked".

My thought for implementation would not be to revive Fjoin as it was;
there are just too many places that deal with targetlists to make it
practical to have an alternative targetlist datastructure for this.
(The reason Fjoin has been too broken to contemplate reviving for all
these years is exactly that there were too many places that had never
coped with it.)  I'd think more about adding a level of projection
(probably embedded in a Result plan node) that expands out the SRF tuple
result into individual columns.

Before that, though, you'd better put forward a workable user interface
for this; I'd wonder in particular what the names of the expanded-out
columns will be, and whether they'd be accessible from places that can
normally see output column names (such as ORDER BY).  And what if a
multi-column function appears in the targetlist of a sub-SELECT?

On the implementation level, I think you will need to face up to the
problem of allowing a tuple value to be embedded as a column of a larger
tuple.  It might be possible to avoid that, but I think it will take
some monstrous kluges to do so.  (The existing pretend-a-TupleTableSlot-
pointer-is-a-Datum approach is already a monstrous kluge, not to mention
a source of memory leaks.)  Once you've fixed that, the existing
FieldSelect expression node probably is all the run-time mechanism
needed to support the projection step I suggested above.

			regards, tom lane

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2002-12-30 02:24:02
Subject: Re: PQescapeString/copy problem.
Previous:From: Kurt RoeckxDate: 2002-12-30 01:23:36
Subject: PQescapeString/copy problem.

pgsql-patches by date

Next:From: Tom LaneDate: 2002-12-30 02:19:55
Subject: Re: point does not return a center of lseg
Previous:From: Joe ConwayDate: 2002-12-30 01:18:08
Subject: Re: [Fwd: SETOF input parameters (was Re: [HACKERS] proposal:

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group