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

SQL: table function support

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 (view raw or flat)
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: tab84.diff
Description: text/x-patch (22.1 KB)

Responses

pgsql-patches by date

Next:From: Decibel!Date: 2008-06-03 20:54:13
Subject: Re: Hint Bits and Write I/O
Previous:From: Jan UrbaƄskiDate: 2008-06-02 15:58:48
Subject: Re: extend VacAttrStats to allow stavalues of different types

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