SETOF input parameters (was Re: [HACKERS] proposal: array utility functions phase 1)

From: Joe Conway <mail(at)joeconway(dot)com>
To: PostgreSQL Patches <pgsql-patches(at)postgresql(dot)org>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: SETOF input parameters (was Re: [HACKERS] proposal: array utility functions phase 1)
Date: 2002-12-13 17:01:49
Message-ID: 3DFA127D.9080101@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-patches

Joe Conway wrote:
> Tom Lane wrote:
>
>> It seems like somehow we need a level of FROM/WHERE producing some base
>> rows, and then a set of table function calls to apply to each of the
>> base rows, and then another level of WHERE to filter the results of the
>> function calls (in particular to provide join conditions to identify
>> which rows to match up in the function outputs). I don't see any way to
>> do this without inventing new SELECT clauses out of whole cloth
>> ... unless SQL99's WITH clause helps, but I don't think it does ...
>
>
> Well, maybe this is a start. It allows a table function's input
> parameter to be declared with setof. The changes involved primarily:
>
> 1) a big loop in ExecMakeTableFunctionResult so that functions with set
> returning arguments get called for each row of the argument,
> and
> 2) aways initializing the tuplestore in ExecMakeTableFunctionResult and
> passing that to the function, even when SFRM_Materialize mode is used.
>
> The result looks like:
>
> create table foot(f1 text, f2 text);
> insert into foot values('a','b');
> insert into foot values('c','d');
> insert into foot values('e','f');
>
> create or replace function test2() returns setof foot as 'select * from
> foot order by 1 asc' language 'sql';
> create or replace function test(setof foot) returns foot as 'select
> $1.f1, $1.f2' language 'sql';
>
> regression=# select * from test(test2());
> f1 | f2
> ----+----
> a | b
> c | d
> e | f
> (3 rows)
>
> I know it doesn't solve all the issues discussed, but is it a step
> forward? Suggestions?
>

The patch was no longer applying cleanly to cvs, so I updated it. Also moved
from HACKERS to PATCHES. Passes all regression tests (well -- geometry still
fails, but that is unrelated).

Joe

Attachment Content-Type Size
tablefunc-setof-input.2.patch text/plain 16.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message snpe 2002-12-13 17:05:25 Re: Big 7.4 items
Previous Message Bruce Momjian 2002-12-13 16:51:12 Re: Big 7.4 items

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2002-12-13 17:02:06 Re: postmaster segfaults when pg_hba.cof is missing
Previous Message Christopher Kings-Lynne 2002-12-13 11:28:05 Re: shows casts, conversions and schemas in psql #2