Different handling of PL/pgSQL for-loop variables in 8.3.7 vs. 8.2.7 ???

From: "Atul Chojar" <achojar(at)airfacts(dot)com>
To: <pgsql-admin(at)postgresql(dot)org>
Cc: "Li" <lilian(dot)ying(at)airfacts(dot)com>, "'Andy Yoder'" <ayoder(at)airfacts(dot)com>
Subject: Different handling of PL/pgSQL for-loop variables in 8.3.7 vs. 8.2.7 ???
Date: 2009-06-10 20:24:25
Message-ID: 002d01c9ea09$7376a390$5a63eab0$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

We recently upgraded from postgres version 8.2.7 to 8.3.7. The below
pl/pgsql test function behaves differently in the 2 versions.

The code of the function is :-

CREATE OR REPLACE FUNCTION "public"."testloop" () RETURNS varchar AS

$body$

BEGIN

FOR idx IN 1..10 LOOP

raise notice 'idx=%', idx;

idx:=idx+1;

END LOOP;

return '';

END;

$body$

LANGUAGE 'plpgsql'

The sql :-

select testloop();

in 8.2.7 returns:-

NOTICE: idx=1

NOTICE: idx=3

NOTICE: idx=5

NOTICE: idx=7

NOTICE: idx=9

But in 8.3.7 returns:-

NOTICE: idx=1

NOTICE: idx=2

NOTICE: idx=3

NOTICE: idx=4

NOTICE: idx=5

NOTICE: idx=6

NOTICE: idx=7

NOTICE: idx=8

NOTICE: idx=9

NOTICE: idx=10

So in 8.3.7, the incrementing of the for-loop variable "idx" is being
ignored; that is not the case in 8.2.7. Is this a new feature of 8.3.7 or a
bug?

Since a lot of our functions depend on manual altering of for-loop
variables, any prompt help/advise/suggestions would be greatly appreciated!

Thanks!

atul

<http://www.airfacts.com/> AirFacts, Inc.
8120 Woodmont Ave., Suite 700
Bethesda, MD 20814
Tel: 301-760-7315

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2009-06-10 20:51:44 Re: Different handling of PL/pgSQL for-loop variables in 8.3.7 vs. 8.2.7 ???
Previous Message Atul Chojar 2009-06-10 20:23:39 Different handling of PL/pgSQL for-loop variables in 8.3.7 vs. 8.2.7 ???

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-06-10 20:51:44 Re: Different handling of PL/pgSQL for-loop variables in 8.3.7 vs. 8.2.7 ???
Previous Message Atul Chojar 2009-06-10 20:23:39 Different handling of PL/pgSQL for-loop variables in 8.3.7 vs. 8.2.7 ???