From 36f00184dcc7597f69466a6e9aa2db6eee1a6ef6 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 8 Aug 2018 20:39:26 +0200 Subject: [PATCH] Improve error messages for CREATE OR REPLACE PROCEDURE Change the hint to recommend DROP PROCEDURE instead of FUNCTION. Also make the error message when changing the return type more specific to the case of procedures. Reported-by: Jeremy Evans --- src/backend/catalog/pg_proc.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c index 9b4015d0d4..654ee943be 100644 --- a/src/backend/catalog/pg_proc.c +++ b/src/backend/catalog/pg_proc.c @@ -375,6 +375,7 @@ ProcedureCreate(const char *procedureName, Form_pg_proc oldproc = (Form_pg_proc) GETSTRUCT(oldtup); Datum proargnames; bool isnull; + const char *prokind_keyword; if (!replace) ereport(ERROR, @@ -400,16 +401,25 @@ ProcedureCreate(const char *procedureName, errdetail("\"%s\" is a window function.", procedureName) : 0))); + prokind_keyword = (prokind == PROKIND_PROCEDURE ? "PROCEDURE" : "FUNCTION"); + /* * Not okay to change the return type of the existing proc, since * existing rules, views, etc may depend on the return type. + * + * In case of a procedure, a changing return type means that whether + * the procedure has output parameters was changed. Since there is no + * user visible return type, we produce a more specific error message. */ if (returnType != oldproc->prorettype || returnsSet != oldproc->proretset) ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), - errmsg("cannot change return type of existing function"), - errhint("Use DROP FUNCTION %s first.", + prokind == PROKIND_PROCEDURE + ? errmsg("cannot change whether a procedure has output parameters") + : errmsg("cannot change return type of existing function"), + errhint("Use DROP %s %s first.", + prokind_keyword, format_procedure(HeapTupleGetOid(oldtup))))); /* @@ -434,7 +444,8 @@ ProcedureCreate(const char *procedureName, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("cannot change return type of existing function"), errdetail("Row type defined by OUT parameters is different."), - errhint("Use DROP FUNCTION %s first.", + errhint("Use DROP %s %s first.", + prokind_keyword, format_procedure(HeapTupleGetOid(oldtup))))); } @@ -477,7 +488,8 @@ ProcedureCreate(const char *procedureName, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("cannot change name of input parameter \"%s\"", old_arg_names[j]), - errhint("Use DROP FUNCTION %s first.", + errhint("Use DROP %s %s first.", + prokind_keyword, format_procedure(HeapTupleGetOid(oldtup))))); } } @@ -501,7 +513,8 @@ ProcedureCreate(const char *procedureName, ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("cannot remove parameter defaults from existing function"), - errhint("Use DROP FUNCTION %s first.", + errhint("Use DROP %s %s first.", + prokind_keyword, format_procedure(HeapTupleGetOid(oldtup))))); proargdefaults = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup, @@ -527,7 +540,8 @@ ProcedureCreate(const char *procedureName, ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("cannot change data type of existing parameter default value"), - errhint("Use DROP FUNCTION %s first.", + errhint("Use DROP %s %s first.", + prokind_keyword, format_procedure(HeapTupleGetOid(oldtup))))); newlc = lnext(newlc); } -- 2.18.0