Commit 4c6cedd1 authored by Heikki Linnakangas's avatar Heikki Linnakangas

Print function signature, not just name, in PL/pgSQL error messages.

This makes it unambiguous which function the message is coming from, if you
have overloaded functions.

Pavel Stehule, reviewed by Abhijit Menon-Sen.
parent 82d4b262
......@@ -342,6 +342,7 @@ do_compile(FunctionCallInfo fcinfo,
compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
function->fn_name = pstrdup(NameStr(procStruct->proname));
function->fn_signature = format_procedure(fcinfo->flinfo->fn_oid);
function->fn_oid = fcinfo->flinfo->fn_oid;
function->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data);
function->fn_tid = procTup->t_self;
......@@ -803,6 +804,7 @@ plpgsql_compile_inline(char *proc_source)
compile_tmp_cxt = MemoryContextSwitchTo(func_cxt);
function->fn_name = pstrdup(func_name);
function->fn_signature = pstrdup(func_name);
function->fn_is_trigger = false;
function->fn_input_collation = InvalidOid;
function->fn_cxt = func_cxt;
......
......@@ -799,7 +799,7 @@ plpgsql_exec_error_callback(void *arg)
* local variable initialization"
*/
errcontext("PL/pgSQL function \"%s\" line %d %s",
estate->func->fn_name,
estate->func->fn_signature,
estate->err_stmt->lineno,
_(estate->err_text));
}
......@@ -810,7 +810,7 @@ plpgsql_exec_error_callback(void *arg)
* arguments into local variables"
*/
errcontext("PL/pgSQL function \"%s\" %s",
estate->func->fn_name,
estate->func->fn_signature,
_(estate->err_text));
}
}
......@@ -818,13 +818,13 @@ plpgsql_exec_error_callback(void *arg)
{
/* translator: last %s is a plpgsql statement type name */
errcontext("PL/pgSQL function \"%s\" line %d at %s",
estate->func->fn_name,
estate->func->fn_signature,
estate->err_stmt->lineno,
plpgsql_stmt_typename(estate->err_stmt));
}
else
errcontext("PL/pgSQL function \"%s\"",
estate->func->fn_name);
estate->func->fn_signature);
}
......
......@@ -679,6 +679,7 @@ typedef struct PLpgSQL_func_hashkey
typedef struct PLpgSQL_function
{ /* Complete compiled function */
char *fn_name;
char *fn_signature;
Oid fn_oid;
TransactionId fn_xmin;
ItemPointerData fn_tid;
......
......@@ -493,7 +493,7 @@ begin
end$$ language plpgsql;
select doubledecrement(3); -- fail because of implicit null assignment
ERROR: domain pos_int does not allow null values
CONTEXT: PL/pgSQL function "doubledecrement" line 3 during statement block local variable initialization
CONTEXT: PL/pgSQL function "doubledecrement(pos_int)" line 3 during statement block local variable initialization
create or replace function doubledecrement(p1 pos_int) returns pos_int as $$
declare v pos_int := 0;
begin
......@@ -501,7 +501,7 @@ begin
end$$ language plpgsql;
select doubledecrement(3); -- fail at initialization assignment
ERROR: value for domain pos_int violates check constraint "pos_int_check"
CONTEXT: PL/pgSQL function "doubledecrement" line 3 during statement block local variable initialization
CONTEXT: PL/pgSQL function "doubledecrement(pos_int)" line 3 during statement block local variable initialization
create or replace function doubledecrement(p1 pos_int) returns pos_int as $$
declare v pos_int := 1;
begin
......@@ -514,10 +514,10 @@ select doubledecrement(0); -- fail before call
ERROR: value for domain pos_int violates check constraint "pos_int_check"
select doubledecrement(1); -- fail at assignment to v
ERROR: value for domain pos_int violates check constraint "pos_int_check"
CONTEXT: PL/pgSQL function "doubledecrement" line 4 at assignment
CONTEXT: PL/pgSQL function "doubledecrement(pos_int)" line 4 at assignment
select doubledecrement(2); -- fail at return
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(pos_int)" while casting return value to function's return type
select doubledecrement(3); -- good
doubledecrement
-----------------
......@@ -566,7 +566,7 @@ end$$ language plpgsql;
select array_elem_check(121.00);
ERROR: numeric field overflow
DETAIL: A field with precision 4, scale 2 must round to an absolute value less than 10^2.
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
CONTEXT: PL/pgSQL function "array_elem_check(numeric)" line 5 at assignment
select array_elem_check(1.23456);
array_elem_check
------------------
......@@ -584,7 +584,7 @@ end$$ language plpgsql;
select array_elem_check(121.00);
ERROR: numeric field overflow
DETAIL: A field with precision 4, scale 2 must round to an absolute value less than 10^2.
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
CONTEXT: PL/pgSQL function "array_elem_check(numeric)" line 5 at assignment
select array_elem_check(1.23456);
array_elem_check
------------------
......@@ -602,7 +602,7 @@ end$$ language plpgsql;
select array_elem_check(121.00);
ERROR: numeric field overflow
DETAIL: A field with precision 4, scale 2 must round to an absolute value less than 10^2.
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
CONTEXT: PL/pgSQL function "array_elem_check(numeric)" line 5 at assignment
select array_elem_check(1.23456);
array_elem_check
------------------
......@@ -650,7 +650,7 @@ select array_elem_check(3);
select array_elem_check(-1);
ERROR: value for domain orderedpair violates check constraint "orderedpair_check"
CONTEXT: PL/pgSQL function "array_elem_check" line 5 at assignment
CONTEXT: PL/pgSQL function "array_elem_check(integer)" line 5 at assignment
drop function array_elem_check(int);
--
-- Renaming
......
......@@ -687,7 +687,7 @@ set work_mem = '1MB';
select myfunc(0);
ERROR: division by zero
CONTEXT: SQL statement "SELECT 1/$1"
PL/pgSQL function "myfunc" line 4 at PERFORM
PL/pgSQL function "myfunc(integer)" line 4 at PERFORM
select current_setting('work_mem');
current_setting
-----------------
......
......@@ -235,7 +235,7 @@ end$$ language plpgsql;
select cachebug();
NOTICE: table "temptable" does not exist, skipping
CONTEXT: SQL statement "drop table if exists temptable cascade"
PL/pgSQL function "cachebug" line 4 at SQL statement
PL/pgSQL function "cachebug()" line 4 at SQL statement
NOTICE: 1
NOTICE: 2
NOTICE: 3
......@@ -247,7 +247,7 @@ NOTICE: 3
select cachebug();
NOTICE: drop cascades to view vv
CONTEXT: SQL statement "drop table if exists temptable cascade"
PL/pgSQL function "cachebug" line 4 at SQL statement
PL/pgSQL function "cachebug()" line 4 at SQL statement
NOTICE: 1
NOTICE: 2
NOTICE: 3
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment