Proposal - Continue stmt for PL/pgSQL

Started by Pavel Stehuleover 20 years ago9 messages
#1Pavel Stehule
stehule@kix.fsv.cvut.cz

Hello

Statement CONTINUE isn't in PL/SQL too, I know it, but Oracle PL/SQL
has statement GOTO. I don't need GOTO statement, but 'continue' can be
very usefull for me. I have to do some ugly trick now. With little change,
we can enhance stmt EXIT for behavior continue.

After some work I can

CREATE OR REPLACE FUNCTION lll() RETURNS void AS $$
DECLARE i integer = 0;
BEGIN
LOOP
i = i + 1;
CONTINUE WHEN i < 10;
RAISE NOTICE '%', i;
EXIT;
END LOOP;
BEGIN
CONTINUE WHEN i = 10;
RAISE NOTICE '---1---';
END;
RAISE NOTICE '---2---';
FOR _i IN 1 .. 10 LOOP
CONTINUE WHEN _i < 5;
RAISE NOTICE '%', _i;
END LOOP;
END; $$ LANGUAGE plpgsql;
select lll();

pokus=# NOTICE: 10
NOTICE: ---2---
NOTICE: 5
NOTICE: 6
NOTICE: 7
NOTICE: 8
NOTICE: 9
NOTICE: 10
lll
-----

(1 row)

What do you think about it? It's broke PL/SQL compatibility, I know, but
via last discussion I have opinion so Oracle compatibility isn't main
objective PL/pgSQL. There is some less/bigger diferencess: SQLSTATE,
EXCEPTION from my last proposal, atd.

What do you think about it?

Regards
Pavel Stehule

#2Josh Berkus
josh@agliodbs.com
In reply to: Pavel Stehule (#1)
Re: Proposal - Continue stmt for PL/pgSQL

Pavel,

   Statement CONTINUE isn't in PL/SQL too, I know it, but Oracle PL/SQL
has statement GOTO. I don't need GOTO statement, but 'continue' can be
very usefull for me. I have to do some ugly trick now. With little change,
we can enhance stmt EXIT for behavior continue.

Can you explain a little better what CONTINUE does that's different from EXIT?

--
Josh Berkus
Aglio Database Solutions
San Francisco

#3Bruno Wolff III
bruno@wolff.to
In reply to: Josh Berkus (#2)
Re: Proposal - Continue stmt for PL/pgSQL

On Thu, Jun 16, 2005 at 09:40:16 -0700,
Josh Berkus <josh@agliodbs.com> wrote:

Pavel,

� �Statement CONTINUE isn't in PL/SQL too, I know it, but Oracle PL/SQL
has statement GOTO. I don't need GOTO statement, but 'continue' can be
very usefull for me. I have to do some ugly trick now. With little change,
we can enhance stmt EXIT for behavior continue.

Can you explain a little better what CONTINUE does that's different from EXIT?

I suspect that CONTINUE is supposed to start the next iteration of the
loop, while EXIT is supposed to terminate the loop.

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Pavel Stehule (#1)
Re: Proposal - Continue stmt for PL/pgSQL

Pavel Stehule <stehule@kix.fsv.cvut.cz> writes:

BEGIN
CONTINUE WHEN i = 10;
RAISE NOTICE '---1---';
END;

I find that really ugly and confusing. If we add a CONTINUE it's only
sensible to allow it inside a loop --- otherwise it's just a nonstandard
spelling of EXIT.

regards, tom lane

#5Andrew Dunstan
andrew@dunslane.net
In reply to: Pavel Stehule (#1)
Re: Proposal - Continue stmt for PL/pgSQL

Pavel Stehule wrote:

What do you think about it? It's broke PL/SQL compatibility, I know, but
via last discussion I have opinion so Oracle compatibility isn't main
objective PL/pgSQL. There is some less/bigger diferencess: SQLSTATE,
EXCEPTION from my last proposal, atd.

Well, yes, but I don't think we should break compatibility
arbitrarilly. I guess it could be argued that this is a missing feature
in PL/SQL and its Ada parent - implementing GOTO just to handle this
case seems unnecessary.

I agree with Tom that it should only be allowed inside a loop.

cheers

andrew

#6Jonah H. Harris
jharris@tvi.edu
In reply to: Andrew Dunstan (#5)
Re: Proposal - Continue stmt for PL/pgSQL

As a near-daily PL/pgSQL developer, I similarly agree.

-Jonah

Andrew Dunstan wrote:

Show quoted text

Pavel Stehule wrote:

What do you think about it? It's broke PL/SQL compatibility, I know,
but via last discussion I have opinion so Oracle compatibility isn't
main objective PL/pgSQL. There is some less/bigger diferencess:
SQLSTATE, EXCEPTION from my last proposal, atd.

Well, yes, but I don't think we should break compatibility
arbitrarilly. I guess it could be argued that this is a missing
feature in PL/SQL and its Ada parent - implementing GOTO just to
handle this case seems unnecessary.

I agree with Tom that it should only be allowed inside a loop.

cheers

andrew

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

#7Pavel Stehule
stehule@kix.fsv.cvut.cz
In reply to: Josh Berkus (#2)
Re: Proposal - Continue stmt for PL/pgSQL

On Thu, 16 Jun 2005, Josh Berkus wrote:

Pavel,

� �Statement CONTINUE isn't in PL/SQL too, I know it, but Oracle PL/SQL
has statement GOTO. I don't need GOTO statement, but 'continue' can be
very usefull for me. I have to do some ugly trick now. With little change,
we can enhance stmt EXIT for behavior continue.

Can you explain a little better what CONTINUE does that's different from EXIT?

continue is equialent next iteration of cycle. exit break cycle. with
block stmt? ~ break and continue are equal.

Pavel

#8Pavel Stehule
stehule@kix.fsv.cvut.cz
In reply to: Tom Lane (#4)
Re: Proposal - Continue stmt for PL/pgSQL

On Thu, 16 Jun 2005, Tom Lane wrote:

Pavel Stehule <stehule@kix.fsv.cvut.cz> writes:

BEGIN
CONTINUE WHEN i = 10;
RAISE NOTICE '---1---';
END;

I find that really ugly and confusing. If we add a CONTINUE it's only
sensible to allow it inside a loop --- otherwise it's just a nonstandard
spelling of EXIT.

I played too much :-). But, there is something wich can complicate
implementation, if I disallow it inside block.

for ... LOOP
begin
continue;
end
end loop;

if I can use continue in begin and block I have easy rules for
implementation. I have to first find any outside loop. But I think it's no
really problem

Pavel Stehule

#9Pavel Stehule
stehule@kix.fsv.cvut.cz
In reply to: Andrew Dunstan (#5)
Re: Proposal - Continue stmt for PL/pgSQL

Well, yes, but I don't think we should break compatibility
arbitrarilly. I guess it could be argued that this is a missing feature
in PL/SQL and its Ada parent - implementing GOTO just to handle this
case seems unnecessary.

Yes. I din't use goto 5 years :-). Continue stmt is more cleaner and
readable.

now:

FOR i IN 1 .. 100 LOOP
continue := true
WHILE continue LOOP
...
EXIT; -- contine
continue := false; -- really exit
END LOOP;
END LOOP;

with continue

FOR i IN 1 .. 100 LOOP
...
EXIT WHEN ..
CONTINUE WHEN ..
END LOOP;

One argument for continue inside begin block - for discussion only.
on loop exit means break iteration, continue new iteration. Continue and
Exit are symmetric.

I didn't know ADA haven't continue. In PL/pgSQL there isn't any problem
implement continue stmt (wit any face), but goto stmt means relative big
changes in source code.

Pavel

Show quoted text

I agree with Tom that it should only be allowed inside a loop.

cheers

andrew

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings