| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> | 
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> | 
| Subject: | Re: Proposal: plpgsql - "for in array" statement | 
| Date: | 2010-09-28 14:34:26 | 
| Message-ID: | 24053.1285684466@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> I looked on some constructs that helps with iteration over array in
> plpgsql. I propose a following syntax:
> FOR var IN [array variable | array expression]
> LOOP
I don't have any opinion about whether the functionality proposed here
is worth the trouble, but I do have an opinion about that syntax: it's
an awful choice.  plpgsql has enough trouble already distinguishing
between integer for-loops and query for-loops, not to mention trouble
in producing a helpful error message when somebody gets either of those
constructs slightly wrong.  Providing a variant where a single
expression can follow IN will make both of those problems an order of
magnitude worse.  As an example, is this a for-in-query or a
for-in-array?
FOR v IN (SELECT arraycol FROM tab) LOOP ...
Either answer is plausible depending on whether you assume the
parentheses make it a subquery.
Pick something less easily confusable with the existing constructs.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2010-09-28 14:41:18 | Re: Proposal: plpgsql - "for in array" statement | 
| Previous Message | Robert Haas | 2010-09-28 14:26:54 | Re: patch: SQL/MED(FDW) DDL |