Skip to content

Commit 4c3754f

Browse files
committed
Fix a few bogus statement type names in plpgsql error messages.
plpgsql's error location context messages ("PL/pgSQL function fn-name line line-no at stmt-type") would misreport a CONTINUE statement as being an EXIT, and misreport a MOVE statement as being a FETCH. These are clear bugs that have been there a long time, so back-patch to all supported branches. In addition, in 9.5 and HEAD, change the description of EXECUTE from "EXECUTE statement" to just plain EXECUTE; there seems no good reason why this statement type should be described differently from others that have a well-defined head keyword. And distinguish GET STACKED DIAGNOSTICS from plain GET DIAGNOSTICS. These are a bit more of a judgment call, and also affect existing regression-test outputs, so I did not back-patch into stable branches. Pavel Stehule and Tom Lane
1 parent f25087d commit 4c3754f

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

src/pl/plpgsql/src/pl_funcs.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
235235
case PLPGSQL_STMT_FOREACH_A:
236236
return _("FOREACH over array");
237237
case PLPGSQL_STMT_EXIT:
238-
return "EXIT";
238+
return ((PLpgSQL_stmt_exit *) stmt)->is_exit ? "EXIT" : "CONTINUE";
239239
case PLPGSQL_STMT_RETURN:
240240
return "RETURN";
241241
case PLPGSQL_STMT_RETURN_NEXT:
@@ -249,15 +249,16 @@ plpgsql_stmt_typename(PLpgSQL_stmt *stmt)
249249
case PLPGSQL_STMT_EXECSQL:
250250
return _("SQL statement");
251251
case PLPGSQL_STMT_DYNEXECUTE:
252-
return _("EXECUTE statement");
252+
return "EXECUTE";
253253
case PLPGSQL_STMT_DYNFORS:
254254
return _("FOR over EXECUTE statement");
255255
case PLPGSQL_STMT_GETDIAG:
256-
return "GET DIAGNOSTICS";
256+
return ((PLpgSQL_stmt_getdiag *) stmt)->is_stacked ?
257+
"GET STACKED DIAGNOSTICS" : "GET DIAGNOSTICS";
257258
case PLPGSQL_STMT_OPEN:
258259
return "OPEN";
259260
case PLPGSQL_STMT_FETCH:
260-
return "FETCH";
261+
return ((PLpgSQL_stmt_fetch *) stmt)->is_move ? "MOVE" : "FETCH";
261262
case PLPGSQL_STMT_CLOSE:
262263
return "CLOSE";
263264
case PLPGSQL_STMT_PERFORM:

src/test/regress/expected/event_trigger.out

+17-17
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ drop cascades to table schema_one."table two"
235235
drop cascades to table schema_one.table_three
236236
NOTICE: table "schema_two_table_two" does not exist, skipping
237237
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_two_table_two"
238-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
238+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
239239
NOTICE: table "audit_tbls_schema_two_table_three" does not exist, skipping
240240
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.audit_tbls_schema_two_table_three"
241-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
241+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
242242
SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_two_table_three"
243-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
243+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
244244
ERROR: object audit_tbls.schema_two_table_three of type table cannot be dropped
245245
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_two_table_three"
246-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
246+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
247247
DELETE FROM undroppable_objs WHERE object_identity = 'audit_tbls.schema_two_table_three';
248248
DROP SCHEMA schema_one, schema_two CASCADE;
249249
NOTICE: drop cascades to 7 other objects
@@ -256,21 +256,21 @@ drop cascades to table schema_one."table two"
256256
drop cascades to table schema_one.table_three
257257
NOTICE: table "schema_two_table_two" does not exist, skipping
258258
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_two_table_two"
259-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
259+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
260260
NOTICE: table "audit_tbls_schema_two_table_three" does not exist, skipping
261261
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.audit_tbls_schema_two_table_three"
262-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
262+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
263263
SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_two_table_three"
264-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
264+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
265265
NOTICE: table "schema_one_table_one" does not exist, skipping
266266
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_one_table_one"
267-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
267+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
268268
NOTICE: table "schema_one_table two" does not exist, skipping
269269
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls."schema_one_table two""
270-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
270+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
271271
NOTICE: table "schema_one_table_three" does not exist, skipping
272272
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_one_table_three"
273-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
273+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
274274
ERROR: object schema_one.table_three of type table cannot be dropped
275275
DELETE FROM undroppable_objs WHERE object_identity = 'schema_one.table_three';
276276
DROP SCHEMA schema_one, schema_two CASCADE;
@@ -284,21 +284,21 @@ drop cascades to table schema_one."table two"
284284
drop cascades to table schema_one.table_three
285285
NOTICE: table "schema_two_table_two" does not exist, skipping
286286
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_two_table_two"
287-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
287+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
288288
NOTICE: table "audit_tbls_schema_two_table_three" does not exist, skipping
289289
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.audit_tbls_schema_two_table_three"
290-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
290+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
291291
SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_two_table_three"
292-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
292+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
293293
NOTICE: table "schema_one_table_one" does not exist, skipping
294294
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_one_table_one"
295-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
295+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
296296
NOTICE: table "schema_one_table two" does not exist, skipping
297297
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls."schema_one_table two""
298-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
298+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
299299
NOTICE: table "schema_one_table_three" does not exist, skipping
300300
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.schema_one_table_three"
301-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
301+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
302302
SELECT * FROM dropped_objects WHERE schema IS NULL OR schema <> 'pg_toast';
303303
type | schema | object
304304
--------------+------------+-------------------------------------
@@ -330,7 +330,7 @@ SELECT * FROM dropped_objects WHERE schema IS NULL OR schema <> 'pg_toast';
330330
DROP OWNED BY regression_bob;
331331
NOTICE: schema "audit_tbls" does not exist, skipping
332332
CONTEXT: SQL statement "DROP TABLE IF EXISTS audit_tbls.audit_tbls_schema_one_table_two"
333-
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE statement
333+
PL/pgSQL function test_evtrig_dropped_objects() line 8 at EXECUTE
334334
SELECT * FROM dropped_objects WHERE type = 'schema';
335335
type | schema | object
336336
--------+--------+------------

src/test/regress/expected/plpgsql.out

+6-6
Original file line numberDiff line numberDiff line change
@@ -3115,7 +3115,7 @@ begin
31153115
end$$ language plpgsql;
31163116
select footest();
31173117
ERROR: query returned no rows
3118-
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE statement
3118+
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE
31193119
create or replace function footest() returns void as $$
31203120
declare x record;
31213121
begin
@@ -3125,7 +3125,7 @@ begin
31253125
end$$ language plpgsql;
31263126
select footest();
31273127
ERROR: query returned more than one row
3128-
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE statement
3128+
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE
31293129
drop function footest();
31303130
-- test printing parameters after failure due to STRICT
31313131
set plpgsql.print_strict_params to true;
@@ -3177,7 +3177,7 @@ end$$ language plpgsql;
31773177
select footest();
31783178
ERROR: query returned no rows
31793179
DETAIL: parameters: $1 = '0', $2 = 'foo'
3180-
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE statement
3180+
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE
31813181
create or replace function footest() returns void as $$
31823182
declare x record;
31833183
begin
@@ -3188,7 +3188,7 @@ end$$ language plpgsql;
31883188
select footest();
31893189
ERROR: query returned more than one row
31903190
DETAIL: parameters: $1 = '1'
3191-
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE statement
3191+
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE
31923192
create or replace function footest() returns void as $$
31933193
declare x record;
31943194
begin
@@ -3198,7 +3198,7 @@ begin
31983198
end$$ language plpgsql;
31993199
select footest();
32003200
ERROR: query returned more than one row
3201-
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE statement
3201+
CONTEXT: PL/pgSQL function footest() line 5 at EXECUTE
32023202
create or replace function footest() returns void as $$
32033203
-- override the global
32043204
#print_strict_params off
@@ -4237,7 +4237,7 @@ end;
42374237
$$ language plpgsql;
42384238
select stacked_diagnostics_test();
42394239
ERROR: GET STACKED DIAGNOSTICS cannot be used outside an exception handler
4240-
CONTEXT: PL/pgSQL function stacked_diagnostics_test() line 6 at GET DIAGNOSTICS
4240+
CONTEXT: PL/pgSQL function stacked_diagnostics_test() line 6 at GET STACKED DIAGNOSTICS
42414241
drop function zero_divide();
42424242
drop function stacked_diagnostics_test();
42434243
-- check cases where implicit SQLSTATE variable could be confused with

src/test/regress/expected/triggers.out

+5-5
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ CONTEXT: SQL statement "insert into depth_b values (new.id)"
14931493
PL/pgSQL function depth_a_tf() line 4 at SQL statement
14941494
NOTICE: depth_c_tr: depth = 3
14951495
CONTEXT: SQL statement "insert into depth_c values (1)"
1496-
PL/pgSQL function depth_b_tf() line 5 at EXECUTE statement
1496+
PL/pgSQL function depth_b_tf() line 5 at EXECUTE
14971497
SQL statement "insert into depth_b values (new.id)"
14981498
PL/pgSQL function depth_a_tf() line 4 at SQL statement
14991499
NOTICE: SQLSTATE = U9999: depth = 2
@@ -1504,12 +1504,12 @@ CONTEXT: SQL statement "insert into depth_b values (new.id)"
15041504
PL/pgSQL function depth_a_tf() line 4 at SQL statement
15051505
NOTICE: depth_c_tr: depth = 3
15061506
CONTEXT: SQL statement "insert into depth_c values (1)"
1507-
PL/pgSQL function depth_b_tf() line 12 at EXECUTE statement
1507+
PL/pgSQL function depth_b_tf() line 12 at EXECUTE
15081508
SQL statement "insert into depth_b values (new.id)"
15091509
PL/pgSQL function depth_a_tf() line 4 at SQL statement
15101510
ERROR: U9999
15111511
CONTEXT: SQL statement "insert into depth_c values (1)"
1512-
PL/pgSQL function depth_b_tf() line 12 at EXECUTE statement
1512+
PL/pgSQL function depth_b_tf() line 12 at EXECUTE
15131513
SQL statement "insert into depth_b values (new.id)"
15141514
PL/pgSQL function depth_a_tf() line 4 at SQL statement
15151515
select pg_trigger_depth();
@@ -1525,12 +1525,12 @@ CONTEXT: SQL statement "insert into depth_b values (new.id)"
15251525
PL/pgSQL function depth_a_tf() line 4 at SQL statement
15261526
NOTICE: depth_c_tr: depth = 3
15271527
CONTEXT: SQL statement "insert into depth_c values (2)"
1528-
PL/pgSQL function depth_b_tf() line 5 at EXECUTE statement
1528+
PL/pgSQL function depth_b_tf() line 5 at EXECUTE
15291529
SQL statement "insert into depth_b values (new.id)"
15301530
PL/pgSQL function depth_a_tf() line 4 at SQL statement
15311531
NOTICE: depth_c_tr: depth = 3
15321532
CONTEXT: SQL statement "insert into depth_c values (2)"
1533-
PL/pgSQL function depth_b_tf() line 5 at EXECUTE statement
1533+
PL/pgSQL function depth_b_tf() line 5 at EXECUTE
15341534
SQL statement "insert into depth_b values (new.id)"
15351535
PL/pgSQL function depth_a_tf() line 4 at SQL statement
15361536
NOTICE: depth_b_tr: depth = 2

0 commit comments

Comments
 (0)