diff options
| author | Neil Conway | 2005-07-02 08:59:48 +0000 |
|---|---|---|
| committer | Neil Conway | 2005-07-02 08:59:48 +0000 |
| commit | c425dcb4ec9ac9aff9e241e0adcf309d2f419ba1 (patch) | |
| tree | 0f56275f049fca1f4d18e561cdfbf14288159ed5 /src/test | |
| parent | 784b948984a529991f86bbefd4013ef98f984996 (diff) | |
In PL/PgSQL, allow a block's label to be optionally specified at the
end of the block:
<<label>>
begin
...
end label;
Similarly for loops. This is per PL/SQL. Update the documentation and
add regression tests. Patch from Pavel Stehule, code review by Neil
Conway.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/plpgsql.out | 59 | ||||
| -rw-r--r-- | src/test/regress/sql/plpgsql.sql | 52 |
2 files changed, 107 insertions, 4 deletions
diff --git a/src/test/regress/expected/plpgsql.out b/src/test/regress/expected/plpgsql.out index a74b0e54666..42dcad5c2fb 100644 --- a/src/test/regress/expected/plpgsql.out +++ b/src/test/regress/expected/plpgsql.out @@ -2491,7 +2491,7 @@ NOTICE: {10,20,30}; 20; xyz; xyzabc; (10,aaa,,30); <NULL> (1 row) drop function raise_exprs(); --- continue statement +-- continue statement create table conttesttbl(idx serial, v integer); NOTICE: CREATE TABLE will create implicit sequence "conttesttbl_idx_seq" for serial column "conttesttbl.idx" insert into conttesttbl(v) values(10); @@ -2532,7 +2532,7 @@ begin for _i in 1..10 loop begin -- applies to outer loop, not the nested begin block - continue when _i < 5; + continue when _i < 5; raise notice '%', _i; end; end loop; @@ -2666,3 +2666,58 @@ drop function continue_test1(); drop function continue_test2(); drop function continue_test3(); drop table conttesttbl; +-- verbose end block and end loop +create function end_label1() returns void as $$ +<<blbl>> +begin + <<flbl1>> + for _i in 1 .. 10 loop + exit flbl1; + end loop flbl1; + <<flbl2>> + for _i in 1 .. 10 loop + exit flbl2; + end loop; +end blbl; +$$ language plpgsql; +select end_label1(); + end_label1 +------------ + +(1 row) + +drop function end_label1(); +-- should fail: undefined end label +create function end_label2() returns void as $$ +begin + for _i in 1 .. 10 loop + exit; + end loop flbl1; +end; +$$ language plpgsql; +ERROR: no such label at or near "flbl1" at character 101 +LINE 5: end loop flbl1; + ^ +-- should fail: end label does not match start label +create function end_label3() returns void as $$ +<<outer_label>> +begin + <<inner_label>> + for _i in 1 .. 10 loop + exit; + end loop outer_label; +end; +$$ language plpgsql; +ERROR: end label "outer_label" differs from block's label "inner_label" +CONTEXT: compile of PL/pgSQL function "end_label3" near line 6 +-- should fail: end label on a block without a start label +create function end_label4() returns void as $$ +<<outer_label>> +begin + for _i in 1 .. 10 loop + exit; + end loop outer_label; +end; +$$ language plpgsql; +ERROR: end label "outer_label" specified for unlabelled block +CONTEXT: compile of PL/pgSQL function "end_label4" near line 5 diff --git a/src/test/regress/sql/plpgsql.sql b/src/test/regress/sql/plpgsql.sql index b0d49c0f321..3432b5556cc 100644 --- a/src/test/regress/sql/plpgsql.sql +++ b/src/test/regress/sql/plpgsql.sql @@ -2113,7 +2113,7 @@ end;$$ language plpgsql; select raise_exprs(); drop function raise_exprs(); --- continue statement +-- continue statement create table conttesttbl(idx serial, v integer); insert into conttesttbl(v) values(10); insert into conttesttbl(v) values(20); @@ -2154,7 +2154,7 @@ begin for _i in 1..10 loop begin -- applies to outer loop, not the nested begin block - continue when _i < 5; + continue when _i < 5; raise notice '%', _i; end; end loop; @@ -2232,3 +2232,51 @@ drop function continue_test1(); drop function continue_test2(); drop function continue_test3(); drop table conttesttbl; + +-- verbose end block and end loop +create function end_label1() returns void as $$ +<<blbl>> +begin + <<flbl1>> + for _i in 1 .. 10 loop + exit flbl1; + end loop flbl1; + <<flbl2>> + for _i in 1 .. 10 loop + exit flbl2; + end loop; +end blbl; +$$ language plpgsql; + +select end_label1(); +drop function end_label1(); + +-- should fail: undefined end label +create function end_label2() returns void as $$ +begin + for _i in 1 .. 10 loop + exit; + end loop flbl1; +end; +$$ language plpgsql; + +-- should fail: end label does not match start label +create function end_label3() returns void as $$ +<<outer_label>> +begin + <<inner_label>> + for _i in 1 .. 10 loop + exit; + end loop outer_label; +end; +$$ language plpgsql; + +-- should fail: end label on a block without a start label +create function end_label4() returns void as $$ +<<outer_label>> +begin + for _i in 1 .. 10 loop + exit; + end loop outer_label; +end; +$$ language plpgsql; |
