Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UGHgE-00048R-PO for pgsql-bugs@arkaria.postgresql.org; Thu, 14 Mar 2013 23:35:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UGHgE-0004wi-15 for pgsql-bugs@arkaria.postgresql.org; Thu, 14 Mar 2013 23:35:26 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UGDwY-0007xc-LM for pgsql-bugs@postgresql.org; Thu, 14 Mar 2013 19:36:02 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UGDwX-0005Wm-C7 for pgsql-bugs@postgresql.org; Thu, 14 Mar 2013 19:36:02 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UGDwW-0000hk-AL for pgsql-bugs@postgresql.org; Thu, 14 Mar 2013 19:36:01 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1UGDwW-0003XF-2l for pgsql-bugs@postgresql.org; Thu, 14 Mar 2013 19:36:00 +0000 Date: Thu, 14 Mar 2013 19:36:00 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #7943: plpgsql parsing bug To: pgsql-bugs@postgresql.org From: rikard@ngs.hr X-Pg-Spam-Score: -4.3 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 7943 Logged by: Rikard Pavelic Email address: rikard@ngs.hr PostgreSQL version: 9.2.1 Operating system: Windows 7 Description:=20=20=20=20=20=20=20=20 ERROR: "_t1" is not a scalar variable LINE 12: for _i1, _i2, _t1, _t2, _t3, _b in select * from ( ^ create type s as ("URI" text, x int); create table t( i int, "some" s[]); create view v as select i::text as "URI", i, "some" from t; create table table_updated (i int, old v, new v); --this works select * from ( SELECT sq.i, sq.xx, cast(sq.old[xx] as s),=20 (select n from unnest(sq.new) n where n."URI" =3D sq.old[xx]."URI"),=20 sq.new[xx],=20 not exists(select o from unnest(sq.old) o where o."URI" =3D sq.new[xx]."UR= I") AND sq.new[xx]::text IS NOT NULL FROM=20 ( SELECT=20 t.i,=20 (t.old)."some" AS old, (t.new)."some" AS new, unnest((SELECT array_agg(x) FROM generate_series(1, CASE WHEN coalesce(array_upper((t.old)."some", 1), 0) > coalesce(array_upper((t.new)."some", 1),0) THEN array_upper((t.old)."some", 1) ELSE array_upper((t.new)."some", 1) END) x)) as xx=20 FROM "table_updated" t ) sq) sq --this throws an error create or replace function fast_select(out i int, out index int, out old s, out s, out new s, out is_new bool) returns setof record as $$ declare _old s[]; declare _new s[]; declare _i1 int; declare _i2 int; declare _t1 s; declare _t2 s; declare _t3 s; declare _b bool; begin for _i1, _i2, _t1, _t2, _t3, _b in select * from ( SELECT sq.i, sq.xx, cast(sq.old[xx] as s),=20 (select n from unnest(sq.new) n where n."URI" =3D sq.old[xx]."URI"),=20 sq.new[xx],=20 not exists(select o from unnest(sq.old) o where o."URI" =3D sq.new[xx]."UR= I") AND sq.new[xx]::text IS NOT NULL FROM=20 ( SELECT=20 t.i,=20 (t.old)."some" AS old, (t.new)."some" AS new, unnest((SELECT array_agg(x) FROM generate_series(1, CASE WHEN coalesce(array_upper((t.old)."some", 1), 0) > coalesce(array_upper((t.new)."some", 1),0) THEN array_upper((t.old)."some", 1) ELSE array_upper((t.new)."some", 1) END) x)) as xx=20 FROM "table_updated" t ) sq) sq loop i =3D _i1; index =3D _i2; old =3D _t1; changed =3D _t2; new =3D _t3; is_new =3D _b; return next; end loop; end $$ language plpgsql; --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs