Remove ancient PL/pgsql line numbering hack.

While this hack arguably has some benefit in terms of making PL/pgsql's
line numbering match the programmer's expectations, it also makes
PL/pgsql inconsistent with the remaining PLs, making it difficult for
clients to reliably determine where the error actually is.  On balance,
it seems better to be consistent.

Pavel Stehule
This commit is contained in:
Robert Haas 2010-08-02 03:46:54 +00:00
parent e621037eec
commit c3a05881de
5 changed files with 31 additions and 44 deletions

View File

@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_scanner.c,v 1.5 2010/02/26 02:01:35 momjian Exp $ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_scanner.c,v 1.6 2010/08/02 03:46:54 rhaas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -519,19 +519,6 @@ location_lineno_init(void)
cur_line_start = scanorig; cur_line_start = scanorig;
cur_line_num = 1; cur_line_num = 1;
/*----------
* Hack: skip any initial newline, so that in the common coding layout
* CREATE FUNCTION ... AS $$
* code body
* $$ LANGUAGE plpgsql;
* we will think "line 1" is what the programmer thinks of as line 1.
*----------
*/
if (*cur_line_start == '\r')
cur_line_start++;
if (*cur_line_start == '\n')
cur_line_start++;
cur_line_end = strchr(cur_line_start, '\n'); cur_line_end = strchr(cur_line_start, '\n');
} }

View File

@ -436,7 +436,7 @@ begin
end$$ language plpgsql; end$$ language plpgsql;
select doubledecrement(3); -- fail because of implicit null assignment select doubledecrement(3); -- fail because of implicit null assignment
ERROR: domain pos_int does not allow null values ERROR: domain pos_int does not allow null values
CONTEXT: PL/pgSQL function "doubledecrement" line 2 during statement block local variable initialization CONTEXT: PL/pgSQL function "doubledecrement" line 3 during statement block local variable initialization
create or replace function doubledecrement(p1 pos_int) returns pos_int as $$ create or replace function doubledecrement(p1 pos_int) returns pos_int as $$
declare v pos_int := 0; declare v pos_int := 0;
begin begin
@ -444,7 +444,7 @@ begin
end$$ language plpgsql; end$$ language plpgsql;
select doubledecrement(3); -- fail at initialization assignment select doubledecrement(3); -- fail at initialization assignment
ERROR: value for domain pos_int violates check constraint "pos_int_check" ERROR: value for domain pos_int violates check constraint "pos_int_check"
CONTEXT: PL/pgSQL function "doubledecrement" line 2 during statement block local variable initialization CONTEXT: PL/pgSQL function "doubledecrement" line 3 during statement block local variable initialization
create or replace function doubledecrement(p1 pos_int) returns pos_int as $$ create or replace function doubledecrement(p1 pos_int) returns pos_int as $$
declare v pos_int := 1; declare v pos_int := 1;
begin begin
@ -457,7 +457,7 @@ select doubledecrement(0); -- fail before call
ERROR: value for domain pos_int violates check constraint "pos_int_check" ERROR: value for domain pos_int violates check constraint "pos_int_check"
select doubledecrement(1); -- fail at assignment to v select doubledecrement(1); -- fail at assignment to v
ERROR: value for domain pos_int violates check constraint "pos_int_check" ERROR: value for domain pos_int violates check constraint "pos_int_check"
CONTEXT: PL/pgSQL function "doubledecrement" line 3 at assignment CONTEXT: PL/pgSQL function "doubledecrement" line 4 at assignment
select doubledecrement(2); -- fail at return select doubledecrement(2); -- fail at return
ERROR: value for domain pos_int violates check constraint "pos_int_check" ERROR: value for domain pos_int violates check constraint "pos_int_check"
CONTEXT: PL/pgSQL function "doubledecrement" while casting return value to function's return type CONTEXT: PL/pgSQL function "doubledecrement" while casting return value to function's return type

View File

@ -686,7 +686,7 @@ set work_mem = '1MB';
select myfunc(0); select myfunc(0);
ERROR: division by zero ERROR: division by zero
CONTEXT: SQL statement "SELECT 1/$1" CONTEXT: SQL statement "SELECT 1/$1"
PL/pgSQL function "myfunc" line 3 at PERFORM PL/pgSQL function "myfunc" line 4 at PERFORM
select current_setting('work_mem'); select current_setting('work_mem');
current_setting current_setting
----------------- -----------------

View File

@ -235,7 +235,7 @@ end$$ language plpgsql;
select cachebug(); select cachebug();
NOTICE: table "temptable" does not exist, skipping NOTICE: table "temptable" does not exist, skipping
CONTEXT: SQL statement "drop table if exists temptable cascade" CONTEXT: SQL statement "drop table if exists temptable cascade"
PL/pgSQL function "cachebug" line 3 at SQL statement PL/pgSQL function "cachebug" line 4 at SQL statement
NOTICE: 1 NOTICE: 1
NOTICE: 2 NOTICE: 2
NOTICE: 3 NOTICE: 3
@ -247,7 +247,7 @@ NOTICE: 3
select cachebug(); select cachebug();
NOTICE: drop cascades to view vv NOTICE: drop cascades to view vv
CONTEXT: SQL statement "drop table if exists temptable cascade" CONTEXT: SQL statement "drop table if exists temptable cascade"
PL/pgSQL function "cachebug" line 3 at SQL statement PL/pgSQL function "cachebug" line 4 at SQL statement
NOTICE: 1 NOTICE: 1
NOTICE: 2 NOTICE: 2
NOTICE: 3 NOTICE: 3

View File

@ -1518,16 +1518,16 @@ ERROR: duplicate key value violates unique constraint "pfield_name"
DETAIL: Key (name)=(PF1_1) already exists. DETAIL: Key (name)=(PF1_1) already exists.
update PSlot set backlink = 'WS.not.there' where slotname = 'PS.base.a1'; update PSlot set backlink = 'WS.not.there' where slotname = 'PS.base.a1';
ERROR: WS.not.there does not exist ERROR: WS.not.there does not exist
CONTEXT: PL/pgSQL function "tg_backlink_a" line 16 at assignment CONTEXT: PL/pgSQL function "tg_backlink_a" line 17 at assignment
update PSlot set backlink = 'XX.illegal' where slotname = 'PS.base.a1'; update PSlot set backlink = 'XX.illegal' where slotname = 'PS.base.a1';
ERROR: illegal backlink beginning with XX ERROR: illegal backlink beginning with XX
CONTEXT: PL/pgSQL function "tg_backlink_a" line 16 at assignment CONTEXT: PL/pgSQL function "tg_backlink_a" line 17 at assignment
update PSlot set slotlink = 'PS.not.there' where slotname = 'PS.base.a1'; update PSlot set slotlink = 'PS.not.there' where slotname = 'PS.base.a1';
ERROR: PS.not.there does not exist ERROR: PS.not.there does not exist
CONTEXT: PL/pgSQL function "tg_slotlink_a" line 16 at assignment CONTEXT: PL/pgSQL function "tg_slotlink_a" line 17 at assignment
update PSlot set slotlink = 'XX.illegal' where slotname = 'PS.base.a1'; update PSlot set slotlink = 'XX.illegal' where slotname = 'PS.base.a1';
ERROR: illegal slotlink beginning with XX ERROR: illegal slotlink beginning with XX
CONTEXT: PL/pgSQL function "tg_slotlink_a" line 16 at assignment CONTEXT: PL/pgSQL function "tg_slotlink_a" line 17 at assignment
insert into HSlot values ('HS', 'base.hub1', 1, ''); insert into HSlot values ('HS', 'base.hub1', 1, '');
ERROR: duplicate key value violates unique constraint "hslot_name" ERROR: duplicate key value violates unique constraint "hslot_name"
DETAIL: Key (slotname)=(HS.base.hub1.1 ) already exists. DETAIL: Key (slotname)=(HS.base.hub1.1 ) already exists.
@ -2067,13 +2067,13 @@ end$$ language plpgsql;
select test_variable_storage(); select test_variable_storage();
NOTICE: should see this NOTICE: should see this
CONTEXT: SQL statement "SELECT trap_zero_divide(-100)" CONTEXT: SQL statement "SELECT trap_zero_divide(-100)"
PL/pgSQL function "test_variable_storage" line 7 at PERFORM PL/pgSQL function "test_variable_storage" line 8 at PERFORM
NOTICE: should see this only if -100 <> 0 NOTICE: should see this only if -100 <> 0
CONTEXT: SQL statement "SELECT trap_zero_divide(-100)" CONTEXT: SQL statement "SELECT trap_zero_divide(-100)"
PL/pgSQL function "test_variable_storage" line 7 at PERFORM PL/pgSQL function "test_variable_storage" line 8 at PERFORM
NOTICE: should see this only if -100 fits in smallint NOTICE: should see this only if -100 fits in smallint
CONTEXT: SQL statement "SELECT trap_zero_divide(-100)" CONTEXT: SQL statement "SELECT trap_zero_divide(-100)"
PL/pgSQL function "test_variable_storage" line 7 at PERFORM PL/pgSQL function "test_variable_storage" line 8 at PERFORM
test_variable_storage test_variable_storage
----------------------- -----------------------
123456789012 123456789012
@ -2302,7 +2302,7 @@ end;
$$ language plpgsql; $$ language plpgsql;
select raise_test1(5); select raise_test1(5);
ERROR: too many parameters specified for RAISE ERROR: too many parameters specified for RAISE
CONTEXT: PL/pgSQL function "raise_test1" line 2 at RAISE CONTEXT: PL/pgSQL function "raise_test1" line 3 at RAISE
create function raise_test2(int) returns int as $$ create function raise_test2(int) returns int as $$
begin begin
raise notice 'This message has too few parameters: %, %, %', $1, $1; raise notice 'This message has too few parameters: %, %, %', $1, $1;
@ -2311,7 +2311,7 @@ end;
$$ language plpgsql; $$ language plpgsql;
select raise_test2(10); select raise_test2(10);
ERROR: too few parameters specified for RAISE ERROR: too few parameters specified for RAISE
CONTEXT: PL/pgSQL function "raise_test2" line 2 at RAISE CONTEXT: PL/pgSQL function "raise_test2" line 3 at RAISE
-- --
-- reject function definitions that contain malformed SQL queries at -- reject function definitions that contain malformed SQL queries at
-- compile-time, where possible -- compile-time, where possible
@ -2424,7 +2424,7 @@ ERROR: column "sqlstate" does not exist
LINE 1: SELECT sqlstate LINE 1: SELECT sqlstate
^ ^
QUERY: SELECT sqlstate QUERY: SELECT sqlstate
CONTEXT: PL/pgSQL function "excpt_test1" line 2 at RAISE CONTEXT: PL/pgSQL function "excpt_test1" line 3 at RAISE
create function excpt_test2() returns void as $$ create function excpt_test2() returns void as $$
begin begin
begin begin
@ -2439,7 +2439,7 @@ ERROR: column "sqlstate" does not exist
LINE 1: SELECT sqlstate LINE 1: SELECT sqlstate
^ ^
QUERY: SELECT sqlstate QUERY: SELECT sqlstate
CONTEXT: PL/pgSQL function "excpt_test2" line 4 at RAISE CONTEXT: PL/pgSQL function "excpt_test2" line 5 at RAISE
create function excpt_test3() returns void as $$ create function excpt_test3() returns void as $$
begin begin
begin begin
@ -2821,7 +2821,7 @@ begin
end$$ language plpgsql; end$$ language plpgsql;
select footest(); select footest();
ERROR: query returned more than one row ERROR: query returned more than one row
CONTEXT: PL/pgSQL function "footest" line 4 at SQL statement CONTEXT: PL/pgSQL function "footest" line 5 at SQL statement
create or replace function footest() returns void as $$ create or replace function footest() returns void as $$
declare x record; declare x record;
begin begin
@ -2884,7 +2884,7 @@ begin
end$$ language plpgsql; end$$ language plpgsql;
select footest(); select footest();
ERROR: query returned no rows ERROR: query returned no rows
CONTEXT: PL/pgSQL function "footest" line 4 at SQL statement CONTEXT: PL/pgSQL function "footest" line 5 at SQL statement
create or replace function footest() returns void as $$ create or replace function footest() returns void as $$
declare x record; declare x record;
begin begin
@ -2894,7 +2894,7 @@ begin
end$$ language plpgsql; end$$ language plpgsql;
select footest(); select footest();
ERROR: query returned more than one row ERROR: query returned more than one row
CONTEXT: PL/pgSQL function "footest" line 4 at SQL statement CONTEXT: PL/pgSQL function "footest" line 5 at SQL statement
create or replace function footest() returns void as $$ create or replace function footest() returns void as $$
declare x record; declare x record;
begin begin
@ -2918,7 +2918,7 @@ begin
end$$ language plpgsql; end$$ language plpgsql;
select footest(); select footest();
ERROR: query returned no rows ERROR: query returned no rows
CONTEXT: PL/pgSQL function "footest" line 4 at EXECUTE statement CONTEXT: PL/pgSQL function "footest" line 5 at EXECUTE statement
create or replace function footest() returns void as $$ create or replace function footest() returns void as $$
declare x record; declare x record;
begin begin
@ -2928,7 +2928,7 @@ begin
end$$ language plpgsql; end$$ language plpgsql;
select footest(); select footest();
ERROR: query returned more than one row ERROR: query returned more than one row
CONTEXT: PL/pgSQL function "footest" line 4 at EXECUTE statement CONTEXT: PL/pgSQL function "footest" line 5 at EXECUTE statement
drop function footest(); drop function footest();
-- test scrollable cursor support -- test scrollable cursor support
create function sc_test() returns setof integer as $$ create function sc_test() returns setof integer as $$
@ -2972,7 +2972,7 @@ $$ language plpgsql;
select * from sc_test(); -- fails because of NO SCROLL specification select * from sc_test(); -- fails because of NO SCROLL specification
ERROR: cursor can only scan forward ERROR: cursor can only scan forward
HINT: Declare it with SCROLL option to enable backward scan. HINT: Declare it with SCROLL option to enable backward scan.
CONTEXT: PL/pgSQL function "sc_test" line 6 at FETCH CONTEXT: PL/pgSQL function "sc_test" line 7 at FETCH
create or replace function sc_test() returns setof integer as $$ create or replace function sc_test() returns setof integer as $$
declare declare
c refcursor; c refcursor;
@ -3559,7 +3559,7 @@ end;
$$ language plpgsql; $$ language plpgsql;
select raise_test(); select raise_test();
ERROR: RAISE option already specified: MESSAGE ERROR: RAISE option already specified: MESSAGE
CONTEXT: PL/pgSQL function "raise_test" line 2 at RAISE CONTEXT: PL/pgSQL function "raise_test" line 3 at RAISE
-- conflict on errcode -- conflict on errcode
create or replace function raise_test() returns void as $$ create or replace function raise_test() returns void as $$
begin begin
@ -3568,7 +3568,7 @@ end;
$$ language plpgsql; $$ language plpgsql;
select raise_test(); select raise_test();
ERROR: RAISE option already specified: ERRCODE ERROR: RAISE option already specified: ERRCODE
CONTEXT: PL/pgSQL function "raise_test" line 2 at RAISE CONTEXT: PL/pgSQL function "raise_test" line 3 at RAISE
-- nothing to re-RAISE -- nothing to re-RAISE
create or replace function raise_test() returns void as $$ create or replace function raise_test() returns void as $$
begin begin
@ -3639,7 +3639,7 @@ select case_test(4);
select case_test(5); -- fails select case_test(5); -- fails
ERROR: case not found ERROR: case not found
HINT: CASE statement is missing ELSE part. HINT: CASE statement is missing ELSE part.
CONTEXT: PL/pgSQL function "case_test" line 4 at CASE CONTEXT: PL/pgSQL function "case_test" line 5 at CASE
select case_test(8); select case_test(8);
case_test case_test
---------------------- ----------------------
@ -3667,7 +3667,7 @@ select case_test(12);
select case_test(13); -- fails select case_test(13); -- fails
ERROR: case not found ERROR: case not found
HINT: CASE statement is missing ELSE part. HINT: CASE statement is missing ELSE part.
CONTEXT: PL/pgSQL function "case_test" line 4 at CASE CONTEXT: PL/pgSQL function "case_test" line 5 at CASE
create or replace function catch() returns void as $$ create or replace function catch() returns void as $$
begin begin
raise notice '%', case_test(6); raise notice '%', case_test(6);
@ -3943,7 +3943,7 @@ LINE 1: SELECT 'foo\\bar\041baz'
^ ^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'. HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
QUERY: SELECT 'foo\\bar\041baz' QUERY: SELECT 'foo\\bar\041baz'
CONTEXT: PL/pgSQL function "strtest" line 3 at RETURN CONTEXT: PL/pgSQL function "strtest" line 4 at RETURN
strtest strtest
------------- -------------
foo\bar!baz foo\bar!baz
@ -4026,7 +4026,7 @@ ERROR: column "foo" does not exist
LINE 1: SELECT rtrim(roomno) AS roomno, foo FROM Room ORDER BY roomn... LINE 1: SELECT rtrim(roomno) AS roomno, foo FROM Room ORDER BY roomn...
^ ^
QUERY: SELECT rtrim(roomno) AS roomno, foo FROM Room ORDER BY roomno QUERY: SELECT rtrim(roomno) AS roomno, foo FROM Room ORDER BY roomno
CONTEXT: PL/pgSQL function "inline_code_block" line 3 at FOR over SELECT rows CONTEXT: PL/pgSQL function "inline_code_block" line 4 at FOR over SELECT rows
-- Check variable scoping -- a var is not available in its own or prior -- Check variable scoping -- a var is not available in its own or prior
-- default expressions. -- default expressions.
create function scope_test() returns int as $$ create function scope_test() returns int as $$
@ -4063,7 +4063,7 @@ LINE 1: select q1,q2 from int8_tbl
^ ^
DETAIL: It could refer to either a PL/pgSQL variable or a table column. DETAIL: It could refer to either a PL/pgSQL variable or a table column.
QUERY: select q1,q2 from int8_tbl QUERY: select q1,q2 from int8_tbl
CONTEXT: PL/pgSQL function "conflict_test" line 4 at FOR over SELECT rows CONTEXT: PL/pgSQL function "conflict_test" line 5 at FOR over SELECT rows
create or replace function conflict_test() returns setof int8_tbl as $$ create or replace function conflict_test() returns setof int8_tbl as $$
#variable_conflict use_variable #variable_conflict use_variable
declare r record; declare r record;