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

proposal, plpgsql, 8.4, for record in cursor

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: proposal, plpgsql, 8.4, for record in cursor
Date: 2007-11-26 15:32:24
Message-ID: 162867790711260732u6a778211s31e29cacb5304b53@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
Hello

I propose new kind of FOR statement .. iteration over cursor, There
are two reasons:

a) better readability of procedure; - SQL statement is outside of statement,

b) better conformance with PL/SQL.

Sample:
CREATE OR REPLACE FUNCTION foo()
RETURNS void AS $$
DECLARE
  c CURSOR(p integer)
    FOR SELECT *
               FROM foot
              WHERE a = p;
BEGIN
  FOR r IN c(10) LOOP
    RAISE NOTICE '%', r.a;
  END LOOP;
  RETURN;
END;
$$ FUNCTION plpgsql;

Syntax:

FOR recordvar IN cursor[ ( params ) ] LOOP
  ..
END LOOP;

Notes:
recordvar is local in statement body (like fori). Used cursor is
automatically opened and closed.

Lot of code can be shared with fors and dynafors (some with stmt_open).

Regards
Pavel Stehule

Responses

pgsql-hackers by date

Next:From: mac_man2005Date: 2007-11-26 15:43:09
Subject: Re: Replacement Selection
Previous:From: Tom LaneDate: 2007-11-26 15:26:24
Subject: Re: plpgsql: another new reserved word

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