From: | Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> |
---|---|
To: | Alvaro Herrera <alvherre(at)commandprompt(dot)com> |
Cc: | Andrew Dunstan <andrew(at)dunslane(dot)net>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Jaime Casanova <jaime(at)2ndquadrant(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: final patch - plpgsql: for-in-array |
Date: | 2010-11-18 20:18:07 |
Message-ID: | AANLkTinuACqiHv3hszU=CHdmbk2i8iE2igXqMgpm0kdy@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
2010/11/18 Alvaro Herrera <alvherre(at)commandprompt(dot)com>:
> Excerpts from Pavel Stehule's message of jue nov 18 17:00:04 -0300 2010:
>> 2010/11/18 Andrew Dunstan <andrew(at)dunslane(dot)net>:
>
>> >> I didn't say so nobody use it. You, me, David. But I really didn't see
>> >> this pattern here in real applications.
>> >>
>> >
>> > Lots of people are told to use it on IRC. Trust me, it's getting well known.
>>
>> can be. but people on IRC are not representative.
>
> Yeah, that's true. I point out usage of unnest to our customers too,
> but it's much more common to see people not using it, instead relying on
> subscripts. People using Postgres show up unexpectedly from under
> rocks, in the weirdest corners; they rarely consult documentation and
> even more rarely get into IRC or mailing list to get help.
>
> I fail to see how this supports the FOR-IN-array development though. It
> will just be another unused construct for most people, no?
maybe I don't understand well, but patch FOR-IN-ARRAY has a documentation
<sect2 id="plpgsql-array-iterating">
+ <title>Looping Through Array</title>
+.
+ <para>
+ The syntax is:
+ <synopsis>
+ <optional> <<<replaceable>label</replaceable>>> </optional>
+ FOR <replaceable>target</replaceable> IN <replaceable>array
expression</replaceable
+ <replaceable>statements</replaceable>
+ END LOOP <optional> <replaceable>label</replaceable> </optional>;
+ </synopsis>
+.
+ The <replaceable>target</replaceable> is a record variable, row variable,
+ or comma-separated list of scalar variables.
+ The <replaceable>target</replaceable> is successively assigned each item
+ of result of the <replaceable>array_expression</replaceable>
and the loop body
+ executed for each item. Here is an example:
+.
+ <programlisting>
+ CREATE TYPE mypt AS (x int, y int);
+.
+ CREATE FUNCTION iterate_over_points() RETURNS void AS $$
+ DECLARE
+ x int; y int;
+ a mypt[] = ARRAY[(10,11),(20,21),(30,31)];
+ BEGIN
+ FOR x, y IN ARRAY a
+ LOOP
+ RAISE NOTICE 'x = %, y = %', x, y;
+ END LOOP;
+ END;
+ $$ LANGUAGE plpgsql;
+ </programlisting>
+.
+ If the loop is terminated by an <literal>EXIT</> statement, the last
+ assigned item value is still accessible after the loop.
+ </para>
+ </sect2>
+.
Pavel
>
> --
> Álvaro Herrera <alvherre(at)commandprompt(dot)com>
> The PostgreSQL Company - Command Prompt, Inc.
> PostgreSQL Replication, Consulting, Custom Development, 24x7 support
>
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2010-11-18 21:13:43 | Re: Latches with weak memory ordering (Re: max_wal_senders must die) |
Previous Message | Alvaro Herrera | 2010-11-18 20:11:32 | Re: final patch - plpgsql: for-in-array |