From: | Andrew Dunstan <andrew(at)dunslane(dot)net> |
---|---|
To: | David Wheeler <david(at)kineticode(dot)com> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: PL/pgSQL 'i = i + 1' Syntax |
Date: | 2006-05-16 23:30:35 |
Message-ID: | 446A609B.9040700@dunslane.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
David Wheeler wrote:
> Hellow PostgreSQL hackers,
>
> Quick question. Why does the 'i = i + 1' syntax work in this PL/pgSQL
> function?
>
> try=# CREATE OR REPLACE FUNCTION inc_by_two(
> try(# upfrom int,
> try(# upto int
> try(# ) RETURNS SETOF INT AS $$
> try$# BEGIN
> try$# FOR i IN upfrom..upto LOOP
> try$# RETURN NEXT i;
> try$# i = i + 1;
> try$# END LOOP;
> try$# END;
> try$# $$ LANGUAGE 'plpgsql';
> CREATE FUNCTION
> try=# select * from inc_by_two(1,10);
> inc_by_two
> ------------
> 1
> 3
> 5
> 7
> 9
> (5 rows)
>
> Someone posted a PL/pgSQL function in my blog with this syntax, which
> is how I know about it, but I couldn't find it documented anywhere. Is
> it a special exception for loop variables, perhaps?
>
It ought to be illegal to modify the loop control variable anyway,
IMNSHO - it certainly is in Ada, the distant antecedent of pl/pgsql.
cheers
andrew
From | Date | Subject | |
---|---|---|---|
Next Message | Mark Dilger | 2006-05-16 23:37:19 | Re: PL/pgSQL 'i = i + 1' Syntax |
Previous Message | David Wheeler | 2006-05-16 23:20:56 | PL/pgSQL 'i = i + 1' Syntax |