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: for-in-array
Description: application/octet-stream (19.8 KB)
Responses
pgsql-hackers by date
| Next: | From: David Fetter | Date: 2010-09-30 13:35:42 |
| Subject: Re: is sync rep stalled? |
| Previous: | From: Andrew Geery | Date: 2010-09-30 12:45:34 |
| Subject: Re: starting to review the Extend NOT NULL representation to
pg_constraint patch |