Proposal - Continue stmt for PL/pgSQL
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
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
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.
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
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
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
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
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
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