By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,177 Members | 976 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,177 IT Pros & Developers. It's quick & easy.

Confused with LABEL and LOOP

P: n/a
Hi,

I'm a bit confused with the use of Label for loops in PostgreSQL.
I'm using PostgreSQL 8.0 Beta2 version on WIN32 platform.

----------------------------------------------------------------------------
--------
CREATE OR REPLACE FUNCTION TEST( ) RETURNS int4 AS '

BEGIN

<<LOOP1>>
LOOP
Raise Notice ''Loop 1'';

EXIT LOOP1;
END LOOP;

RETURN 0;

END'
LANGUAGE 'plpgsql';
----------------------------------------------------------------------------
--------

When I call SELECT TEST(), I get the error message :
ERROR: control reached end of function without RETURN
CONTEXT: PL/pgSQL function "test"

If I just change EXIT LOOP1 to EXIT -> everything is OK
I think we previously had the possibility to indicate the LABEL in EXIT
statement...

Regards,

Patrick

---------------------------------------------------------------------------
----------------
Patrick Fiche
email : pa***********@aqsacom.com
----------------------------------------------------------------------------
---------------


Protected by Polesoft Lockspam
http://www.polesoft.com/refer.html

Nov 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Patrick Fiche" <pa***********@aqsacom.com> writes:
I'm a bit confused with the use of Label for loops in PostgreSQL.
I'm using PostgreSQL 8.0 Beta2 version on WIN32 platform. CREATE OR REPLACE FUNCTION TEST( ) RETURNS int4 AS '
BEGIN
<<LOOP1>>
LOOP
Raise Notice ''Loop 1'';
EXIT LOOP1;
END LOOP;
RETURN 0;
END'
LANGUAGE 'plpgsql'; When I call SELECT TEST(), I get the error message :
ERROR: control reached end of function without RETURN
CONTEXT: PL/pgSQL function "test"


Hmm. I think this *should* work, and experimentation shows that it did
work up through PG 7.2. It's broken in 7.3 and later.

Jan, do you see any fine point that makes this function wrong? Sure
looks like a bug to me.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #2

P: n/a
Tom Lane <tg*@sss.pgh.pa.us> writes:
"Patrick Fiche" <pa***********@aqsacom.com> writes:
I'm a bit confused with the use of Label for loops in PostgreSQL.
Sure looks like a bug to me.


Ah-hah: it's a case-sensitivity problem. The <<>> construct downcases
its label identifier, but EXIT forgets to do so. Spell it as
"EXIT loop1" and you'll be OK.

I'll fix this for 8.0.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.