PL/pgSQL proposal: using list of scalars in assign stmts, fore and fors stmts

From: "Pavel Stehule" <pavel(dot)stehule(at)hotmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: PL/pgSQL proposal: using list of scalars in assign stmts, fore and fors stmts
Date: 2005-12-22 09:18:16
Message-ID: BAY20-F2006DAA09F8162F0A40FC4F9300@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

Now, statements EXECUTE INTO and SELECT INTO allow using list of scalars.
FORe and FORs allow only ROW o RECORD VARIABLE. I'll plan and I did it
enhance this stmts:

<for> := FOR <target> IN {SELECT | EXECUTE} ... LOOP
<target> := {row|record|comma separated list of scalar vars}

<assign> := <target2> ':=' <expression>
<target2> := {row|record|variable|'ROW(' comma separated list of scalar vars
')'}

for example:
CREATE OR REPLACE FUNCTION test(OUT _rc, OUT _x varchar, OUT _y varchar)
RETURNS SETOF RECORD AS $$
DECLARE _r RECORD;
BEGIN
rc := 0;
-- old style;
FOR _r IN SELECT generate_series AS x, generateseries + 1 AS y FROM
generate_series(1,4) LOOP
_rc := _rc + 1; _x := _r.x; _y := _r.y;
RETURN NEXT;
END LOOP;
-- new one
FOR _x,_y IN SELECT generate_series, generateseries + 1 FROM
generate_series(1,4) LOOP
_rc := _rc + 1;
RETURN NEXT;
END LOOP;
-- new two
FOR _r IN SELECT generate_series AS x, generateseries + 1 AS y FROM
generate_series(1,4) LOOP
_rc := _rc + 1; ROW(_x,_y) := _r;
RETURN NEXT;
END LOOP;
RETURN;
END; $$ LANGUAGE plpgsql;

any comments?
Regards
Pavel Stehule

_________________________________________________________________
Najdete si svou lasku a nove pratele na Match.com. http://www.msn.cz/

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message REYNAUD Jean-Samuel 2005-12-22 09:52:58 Re: Function call with offset and limit
Previous Message Lukas Smith 2005-12-22 08:35:57 Re: Automatic function replanning