diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c index 654ee943be..87d4850c11 100644 --- a/src/backend/catalog/pg_proc.c +++ b/src/backend/catalog/pg_proc.c @@ -375,7 +375,7 @@ ProcedureCreate(const char *procedureName, Form_pg_proc oldproc = (Form_pg_proc) GETSTRUCT(oldtup); Datum proargnames; bool isnull; - const char *prokind_keyword; + bool isprocedure; if (!replace) ereport(ERROR, @@ -401,7 +401,8 @@ ProcedureCreate(const char *procedureName, errdetail("\"%s\" is a window function.", procedureName) : 0))); - prokind_keyword = (prokind == PROKIND_PROCEDURE ? "PROCEDURE" : "FUNCTION"); + /* Store if this is a procedure/function to help with errors/hints */ + isprocedure = (prokind == PROKIND_PROCEDURE); /* * Not okay to change the return type of the existing proc, since @@ -415,12 +416,14 @@ ProcedureCreate(const char *procedureName, returnsSet != oldproc->proretset) ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), - 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))))); + isprocedure ? + errmsg("cannot change whether a procedure has output parameters") : + errmsg("cannot change return type of existing function"), + isprocedure ? + errhint("Use DROP PROCEDURE %s first.", + format_procedure(HeapTupleGetOid(oldtup))) : + errhint("Use DROP FUNCTION %s first.", + format_procedure(HeapTupleGetOid(oldtup))))); /* * If it returns RECORD, check for possible change of record type @@ -444,9 +447,11 @@ 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 %s %s first.", - prokind_keyword, - format_procedure(HeapTupleGetOid(oldtup))))); + isprocedure ? + errhint("Use DROP PROCEDURE %s first.", + format_procedure(HeapTupleGetOid(oldtup))) : + errhint("Use DROP FUNCTION %s first.", + format_procedure(HeapTupleGetOid(oldtup))))); } /* @@ -488,9 +493,11 @@ ProcedureCreate(const char *procedureName, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("cannot change name of input parameter \"%s\"", old_arg_names[j]), - errhint("Use DROP %s %s first.", - prokind_keyword, - format_procedure(HeapTupleGetOid(oldtup))))); + isprocedure ? + errhint("Use DROP PROCEDURE %s first.", + format_procedure(HeapTupleGetOid(oldtup))) : + errhint("Use DROP FUNCTION %s first.", + format_procedure(HeapTupleGetOid(oldtup))))); } } @@ -513,9 +520,11 @@ ProcedureCreate(const char *procedureName, ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("cannot remove parameter defaults from existing function"), - errhint("Use DROP %s %s first.", - prokind_keyword, - format_procedure(HeapTupleGetOid(oldtup))))); + isprocedure ? + errhint("Use DROP PROCEDURE %s first.", + format_procedure(HeapTupleGetOid(oldtup))) : + errhint("Use DROP FUNCTION %s first.", + format_procedure(HeapTupleGetOid(oldtup))))); proargdefaults = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup, Anum_pg_proc_proargdefaults, @@ -540,9 +549,11 @@ ProcedureCreate(const char *procedureName, ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("cannot change data type of existing parameter default value"), - errhint("Use DROP %s %s first.", - prokind_keyword, - format_procedure(HeapTupleGetOid(oldtup))))); + isprocedure ? + errhint("Use DROP PROCEDURE %s first.", + format_procedure(HeapTupleGetOid(oldtup))) : + errhint("Use DROP FUNCTION %s first.", + format_procedure(HeapTupleGetOid(oldtup))))); newlc = lnext(newlc); } }