final patch - plpgsql: for-in-array

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: final patch - plpgsql: for-in-array
Date: 2010-09-30 12:46:02
Message-ID: AANLkTinqzqUCy++vpkN27=8dr2ADuoz0L9nSRozADt6J@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello

this patch implement a new iteration construct - iteration over an
array. The sense of this new iteration is:
* a simple and cleaner syntax
* a faster execution - this bring down a number of detoast operations

create or replace function subscripts(anyarray, int)
returns int[] as $$
select array(select generate_subscripts($1,$2));
$$ language sql;

create or replace function fora_test()
returns int as $$
declare x int; s int = 0;
a int[] := array[1,2,3,4,5,6,7,8,9,10];
begin
for x in array subscripts(a, 1)
loop
s := s + a[x];
end loop;
return s;
end;
$$ language plpgsql;

create or replace function fora_test()
returns int as $$
declare x int; s int = 0;
begin
for x in array array[1,2,3,4,5,6,7,8,9,10]
loop
s := s + x;
end loop;
return s;
end;
$$ language plpgsql;

create or replace function fora_test()
returns int as $$
declare x int; y int;
a fora_point[] := array[(1,2),(3,4),(5,6)];
begin
for x, y in array a
loop
raise notice 'point=%,%', x, y;
end loop;
return 0;
end;
$$ language plpgsql;

Regards

Pavel Stehule

Attachment Content-Type Size
for-in-array application/octet-stream 19.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Fetter 2010-09-30 13:35:42 Re: is sync rep stalled?
Previous Message Andrew Geery 2010-09-30 12:45:34 Re: starting to review the Extend NOT NULL representation to pg_constraint patch