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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

proposal, plpgsql, 8.4, for record in cursor



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



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group