From: | "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | pgsql-patches <pgsql-patches(at)postgresql(dot)org> |
Subject: | SQL: table function support |
Date: | 2008-06-03 11:03:06 |
Message-ID: | 162867790806030403r221a6ae3s657f78ad2da9237f@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-patches |
Hello
this patch add support of table functions syntax like ANSI SQL 2003.
CREATE OR REPLACE FUNCTION foo_sql(integer)
RETURNS TABLE(a integer, b integer, c integer) AS $$
SELECT i, i+1, i+2
FROM generate_series(1, $1) g(i);
$$ LANGUAGE sql;
CREATE OR REPLACE FUNCTION foo_plpgsql1(m integer)
RETURNS TABLE(a integer, b integer, c integer) AS $$
DECLARE r record;
BEGIN
FOR i IN 1..m LOOP
r = ROW(i, i+1, i+2);
RETURN NEXT r;
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION foo_plpgsql2(m integer)
RETURNS TABLE(a integer, b integer, c integer) AS $$
DECLARE r record;
BEGIN
RETURN QUERY
SELECT i, i+1, i+2
FROM generate_series(1, m) g(i);
RETURN;
END;
$$ LANGUAGE plpgsql;
There are one significant difference to SRF with OUT variables.
Attributies declared in TABLE clause doesn't create local variables.
It's in conformance with SQL/PSM.
Regards
Pavel Stehule
Attachment | Content-Type | Size |
---|---|---|
tab84.diff | text/x-patch | 22.1 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Decibel! | 2008-06-03 20:54:13 | Re: Hint Bits and Write I/O |
Previous Message | Jan Urbański | 2008-06-02 15:58:48 | Re: extend VacAttrStats to allow stavalues of different types |