Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4c6cedd

Browse files
committed
Print function signature, not just name, in PL/pgSQL error messages.
This makes it unambiguous which function the message is coming from, if youhave overloaded functions.Pavel Stehule, reviewed by Abhijit Menon-Sen.
1 parent82d4b26 commit4c6cedd

File tree

8 files changed

+91
-88
lines changed

8 files changed

+91
-88
lines changed

‎src/pl/plpgsql/src/pl_comp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ do_compile(FunctionCallInfo fcinfo,
342342
compile_tmp_cxt=MemoryContextSwitchTo(func_cxt);
343343

344344
function->fn_name=pstrdup(NameStr(procStruct->proname));
345+
function->fn_signature=format_procedure(fcinfo->flinfo->fn_oid);
345346
function->fn_oid=fcinfo->flinfo->fn_oid;
346347
function->fn_xmin=HeapTupleHeaderGetXmin(procTup->t_data);
347348
function->fn_tid=procTup->t_self;
@@ -803,6 +804,7 @@ plpgsql_compile_inline(char *proc_source)
803804
compile_tmp_cxt=MemoryContextSwitchTo(func_cxt);
804805

805806
function->fn_name=pstrdup(func_name);
807+
function->fn_signature=pstrdup(func_name);
806808
function->fn_is_trigger= false;
807809
function->fn_input_collation=InvalidOid;
808810
function->fn_cxt=func_cxt;

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ plpgsql_exec_error_callback(void *arg)
799799
* local variable initialization"
800800
*/
801801
errcontext("PL/pgSQL function \"%s\" line %d %s",
802-
estate->func->fn_name,
802+
estate->func->fn_signature,
803803
estate->err_stmt->lineno,
804804
_(estate->err_text));
805805
}
@@ -810,21 +810,21 @@ plpgsql_exec_error_callback(void *arg)
810810
* arguments into local variables"
811811
*/
812812
errcontext("PL/pgSQL function \"%s\" %s",
813-
estate->func->fn_name,
813+
estate->func->fn_signature,
814814
_(estate->err_text));
815815
}
816816
}
817817
elseif (estate->err_stmt!=NULL)
818818
{
819819
/* translator: last %s is a plpgsql statement type name */
820820
errcontext("PL/pgSQL function \"%s\" line %d at %s",
821-
estate->func->fn_name,
821+
estate->func->fn_signature,
822822
estate->err_stmt->lineno,
823823
plpgsql_stmt_typename(estate->err_stmt));
824824
}
825825
else
826826
errcontext("PL/pgSQL function \"%s\"",
827-
estate->func->fn_name);
827+
estate->func->fn_signature);
828828
}
829829

830830

‎src/pl/plpgsql/src/plpgsql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ typedef struct PLpgSQL_func_hashkey
679679
typedefstructPLpgSQL_function
680680
{/* Complete compiled function */
681681
char*fn_name;
682+
char*fn_signature;
682683
Oidfn_oid;
683684
TransactionIdfn_xmin;
684685
ItemPointerDatafn_tid;

‎src/test/regress/expected/domain.out

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,15 @@ begin
493493
end$$ language plpgsql;
494494
select doubledecrement(3); -- fail because of implicit null assignment
495495
ERROR: domain pos_int does not allow null values
496-
CONTEXT: PL/pgSQL function "doubledecrement" line 3 during statement block local variable initialization
496+
CONTEXT: PL/pgSQL function "doubledecrement(pos_int)" line 3 during statement block local variable initialization
497497
create or replace function doubledecrement(p1 pos_int) returns pos_int as $$
498498
declare v pos_int := 0;
499499
begin
500500
return p1;
501501
end$$ language plpgsql;
502502
select doubledecrement(3); -- fail at initialization assignment
503503
ERROR: value for domain pos_int violates check constraint "pos_int_check"
504-
CONTEXT: PL/pgSQL function "doubledecrement" line 3 during statement block local variable initialization
504+
CONTEXT: PL/pgSQL function "doubledecrement(pos_int)" line 3 during statement block local variable initialization
505505
create or replace function doubledecrement(p1 pos_int) returns pos_int as $$
506506
declare v pos_int := 1;
507507
begin
@@ -514,10 +514,10 @@ select doubledecrement(0); -- fail before call
514514
ERROR: value for domain pos_int violates check constraint "pos_int_check"
515515
select doubledecrement(1); -- fail at assignment to v
516516
ERROR: value for domain pos_int violates check constraint "pos_int_check"
517-
CONTEXT: PL/pgSQL function "doubledecrement" line 4 at assignment
517+
CONTEXT: PL/pgSQL function "doubledecrement(pos_int)" line 4 at assignment
518518
select doubledecrement(2); -- fail at return
519519
ERROR: value for domain pos_int violates check constraint "pos_int_check"
520-
CONTEXT: PL/pgSQL function "doubledecrement" while casting return value to function's return type
520+
CONTEXT: PL/pgSQL function "doubledecrement(pos_int)" while casting return value to function's return type
521521
select doubledecrement(3); -- good
522522
doubledecrement
523523
-----------------
@@ -566,7 +566,7 @@ end$$ language plpgsql;
566566
select array_elem_check(121.00);
567567
ERROR: numeric field overflow
568568
DETAIL: A field with precision 4, scale 2 must round to an absolute value less than 10^2.
569-
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
569+
CONTEXT: PL/pgSQL function "array_elem_check(numeric)" line 5 at assignment
570570
select array_elem_check(1.23456);
571571
array_elem_check
572572
------------------
@@ -584,7 +584,7 @@ end$$ language plpgsql;
584584
select array_elem_check(121.00);
585585
ERROR: numeric field overflow
586586
DETAIL: A field with precision 4, scale 2 must round to an absolute value less than 10^2.
587-
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
587+
CONTEXT: PL/pgSQL function "array_elem_check(numeric)" line 5 at assignment
588588
select array_elem_check(1.23456);
589589
array_elem_check
590590
------------------
@@ -602,7 +602,7 @@ end$$ language plpgsql;
602602
select array_elem_check(121.00);
603603
ERROR: numeric field overflow
604604
DETAIL: A field with precision 4, scale 2 must round to an absolute value less than 10^2.
605-
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
605+
CONTEXT: PL/pgSQL function "array_elem_check(numeric)" line 5 at assignment
606606
select array_elem_check(1.23456);
607607
array_elem_check
608608
------------------
@@ -650,7 +650,7 @@ select array_elem_check(3);
650650

651651
select array_elem_check(-1);
652652
ERROR: value for domain orderedpair violates check constraint "orderedpair_check"
653-
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
653+
CONTEXT: PL/pgSQL function "array_elem_check(integer)" line 5 at assignment
654654
drop function array_elem_check(int);
655655
--
656656
-- Renaming

‎src/test/regress/expected/guc.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ set work_mem = '1MB';
687687
select myfunc(0);
688688
ERROR: division by zero
689689
CONTEXT: SQL statement "SELECT 1/$1"
690-
PL/pgSQL function "myfunc" line 4 at PERFORM
690+
PL/pgSQL function "myfunc(integer)" line 4 at PERFORM
691691
select current_setting('work_mem');
692692
current_setting
693693
-----------------

‎src/test/regress/expected/plancache.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ end$$ language plpgsql;
235235
select cachebug();
236236
NOTICE: table "temptable" does not exist, skipping
237237
CONTEXT: SQL statement "drop table if exists temptable cascade"
238-
PL/pgSQL function "cachebug" line 4 at SQL statement
238+
PL/pgSQL function "cachebug()" line 4 at SQL statement
239239
NOTICE: 1
240240
NOTICE: 2
241241
NOTICE: 3
@@ -247,7 +247,7 @@ NOTICE: 3
247247
select cachebug();
248248
NOTICE: drop cascades to view vv
249249
CONTEXT: SQL statement "drop table if exists temptable cascade"
250-
PL/pgSQL function "cachebug" line 4 at SQL statement
250+
PL/pgSQL function "cachebug()" line 4 at SQL statement
251251
NOTICE: 1
252252
NOTICE: 2
253253
NOTICE: 3

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp