2010/11/18 Alvaro Herrera <alvherre@commandprompt.com>:
> Excerpts from Pavel Stehule's message of jue nov 18 17:00:04 -0300 2010:
>> 2010/11/18 Andrew Dunstan <andrew@dunslane.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@commandprompt.com>
> The PostgreSQL Company - Command Prompt, Inc.
> PostgreSQL Replication, Consulting, Custom Development, 24x7 support
>