On Mon, Jan 24, 2011 at 20:10, Pavel Stehule <pavel.steh...@gmail.com> wrote: > we have to iterate over array's items because it allow seq. access to > array's data. I need a global index for function "array_get_isnull". I > can't to use a buildin functions like array_slize_size or > array_get_slice, because there is high overhead of array_seek > function. I redesigned the initial part of main cycle, but code is > little bit longer :(, but I hope, it is more readable.
The attached patch only includes changes in plpgsql. I tested it combined with the previous one, that includes other directories. * src/pl/plpgsql/src/gram.y | for_variable K_SLICE ICONST The parameter for SLICE must be an integer literal. Is it a design? I got a syntax error when I wrote a function like below. However, FOREACH returns different types on SLICE = 0 or SLICE >= 1. (element type for 0, or array type for >=1) So, we cannot write a true generic function that accepts all SLICE values even if the syntax supports an expr for the parameter. CREATE FUNCTION foreach_test(int[], int) RETURNS SETOF int[] AS $$ DECLARE a integer[]; BEGIN FOREACH a SLICE $2 IN $1 LOOP -- syntax error RETURN NEXT a; END LOOP; END; $$ LANGUAGE plpgsql; * /doc/src/sgml/plpgsql.sgml + FOREACH <replaceable>target</replaceable> <optional> SCALE s/SCALE/SLICE/ ? * Why do you use "foreach_a" for some identifiers? We use "foreach" only for arrays, so "_a" suffix doesn't seem needed. * accumArrayResult() for SLICE has a bit overhead. If we want to optimize it, we could use memcpy() because slices are placed in continuous memory. But I'm not sure the worth; I guess FOREACH will be used with SLICE = 0 in many cases. -- Itagaki Takahiro -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers