SQL: table function support - Mailing list pgsql-patches

From Pavel Stehule
Subject SQL: table function support
Date
Msg-id 162867790806030403r221a6ae3s657f78ad2da9237f@mail.gmail.com
Whole thread Raw
Responses Re: SQL: table function support  (Neil Conway <neilc@samurai.com>)
List 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

pgsql-patches by date:

Previous
From: Jan Urbański
Date:
Subject: Re: extend VacAttrStats to allow stavalues of different types
Next
From: "Heikki Linnakangas"
Date:
Subject: Re: Free Space Map rewrite