Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0caa0d0

Browse files
committed
Make DROP FUNCTION hint more informative.
If you decide you want to take the hint, this gives you something you can paste right back to the server. Dean Rasheed
1 parent 76837c1 commit 0caa0d0

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/backend/catalog/pg_proc.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ ProcedureCreate(const char *procedureName,
404404
ereport(ERROR,
405405
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
406406
errmsg("cannot change return type of existing function"),
407-
errhint("Use DROP FUNCTION first.")));
407+
errhint("Use DROP FUNCTION %s first.",
408+
format_procedure(HeapTupleGetOid(oldtup)))));
408409

409410
/*
410411
* If it returns RECORD, check for possible change of record type
@@ -427,7 +428,8 @@ ProcedureCreate(const char *procedureName,
427428
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
428429
errmsg("cannot change return type of existing function"),
429430
errdetail("Row type defined by OUT parameters is different."),
430-
errhint("Use DROP FUNCTION first.")));
431+
errhint("Use DROP FUNCTION %s first.",
432+
format_procedure(HeapTupleGetOid(oldtup)))));
431433
}
432434

433435
/*
@@ -469,7 +471,8 @@ ProcedureCreate(const char *procedureName,
469471
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
470472
errmsg("cannot change name of input parameter \"%s\"",
471473
old_arg_names[j]),
472-
errhint("Use DROP FUNCTION first.")));
474+
errhint("Use DROP FUNCTION %s first.",
475+
format_procedure(HeapTupleGetOid(oldtup)))));
473476
}
474477
}
475478

@@ -492,7 +495,8 @@ ProcedureCreate(const char *procedureName,
492495
ereport(ERROR,
493496
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
494497
errmsg("cannot remove parameter defaults from existing function"),
495-
errhint("Use DROP FUNCTION first.")));
498+
errhint("Use DROP FUNCTION %s first.",
499+
format_procedure(HeapTupleGetOid(oldtup)))));
496500

497501
proargdefaults = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup,
498502
Anum_pg_proc_proargdefaults,
@@ -518,7 +522,8 @@ ProcedureCreate(const char *procedureName,
518522
ereport(ERROR,
519523
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
520524
errmsg("cannot change data type of existing parameter default value"),
521-
errhint("Use DROP FUNCTION first.")));
525+
errhint("Use DROP FUNCTION %s first.",
526+
format_procedure(HeapTupleGetOid(oldtup)))));
522527
newlc = lnext(newlc);
523528
}
524529
}

src/test/regress/expected/polymorphism.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ select dfunc(10,20);
10261026
create or replace function dfunc(a variadic int[]) returns int as
10271027
$$ select array_upper($1, 1) $$ language sql;
10281028
ERROR: cannot remove parameter defaults from existing function
1029-
HINT: Use DROP FUNCTION first.
1029+
HINT: Use DROP FUNCTION dfunc(integer[]) first.
10301030
\df dfunc
10311031
List of functions
10321032
Schema | Name | Result data type | Argument data types | Type
@@ -1239,13 +1239,13 @@ returns record as $$
12391239
select $1, $2;
12401240
$$ language sql;
12411241
ERROR: cannot change name of input parameter "c"
1242-
HINT: Use DROP FUNCTION first.
1242+
HINT: Use DROP FUNCTION dfunc(character varying,numeric) first.
12431243
create or replace function dfunc(a varchar = 'def a', out _a varchar, numeric = NULL, out _c numeric)
12441244
returns record as $$
12451245
select $1, $2;
12461246
$$ language sql;
12471247
ERROR: cannot change name of input parameter "c"
1248-
HINT: Use DROP FUNCTION first.
1248+
HINT: Use DROP FUNCTION dfunc(character varying,numeric) first.
12491249
drop function dfunc(varchar, numeric);
12501250
--fail, named parameters are not unique
12511251
create function testfoo(a int, a int) returns int as $$ select 1;$$ language sql;

src/test/regress/expected/rangefuncs.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ CREATE OR REPLACE FUNCTION foo(in f1 int, out f2 int, out f3 text)
439439
RETURNS record
440440
AS 'select $1+1' LANGUAGE sql;
441441
ERROR: cannot change return type of existing function
442-
HINT: Use DROP FUNCTION first.
442+
HINT: Use DROP FUNCTION foo(integer) first.
443443
CREATE OR REPLACE FUNCTION foor(in f1 int, out f2 int, out text)
444444
AS $$select $1-1, $1::text || 'z'$$ LANGUAGE sql;
445445
SELECT f1, foor(f1) FROM int4_tbl;
@@ -521,7 +521,7 @@ SELECT * FROM dup('xyz'::text);
521521
CREATE OR REPLACE FUNCTION dup (inout f2 anyelement, out f3 anyarray)
522522
AS 'select $1, array[$1,$1]' LANGUAGE sql;
523523
ERROR: cannot change name of input parameter "f1"
524-
HINT: Use DROP FUNCTION first.
524+
HINT: Use DROP FUNCTION dup(anyelement) first.
525525
DROP FUNCTION dup(anyelement);
526526
-- equivalent behavior, though different name exposed for input arg
527527
CREATE OR REPLACE FUNCTION dup (inout f2 anyelement, out f3 anyarray)

0 commit comments

Comments
 (0)