Fix hints on CREATE PROCEDURE errors - Mailing list pgsql-hackers

From Jeremy Evans
Subject Fix hints on CREATE PROCEDURE errors
Date
Msg-id 20180806183205.GB42466@jeremyevans.local
Whole thread Raw
Responses Re: Fix hints on CREATE PROCEDURE errors
Re: Fix hints on CREATE PROCEDURE errors
List pgsql-hackers
When testing out CREATE PROCEDURE with 11 beta 2, I noticed, the hints
in the errors reference DROP FUNCTION, which doesn't work for
procedures.  DROP ROUTINE works for both functions and procedures, so
this patch should work for both.

Please CC me when responding as I don't currently subscribe to the
list.

Thanks,
Jeremy


From 1e4880e77b2b11917021e9d46756264013bd87d5 Mon Sep 17 00:00:00 2001
From: Jeremy Evans <code@jeremyevans.net>
Date: Mon, 6 Aug 2018 11:01:00 -0700
Subject: [PATCH] Have hint use DROP ROUTINE instead of DROP FUNCTION

The current code's hint is misleading for procedures:

CREATE OR REPLACE PROCEDURE a(in int)
LANGUAGE SQL
AS $$
SELECT NULL;
$$;
# CREATE PROCEDURE

CREATE OR REPLACE PROCEDURE a(inout int)
LANGUAGE SQL
AS $$
SELECT NULL;
$$;
# ERROR:  cannot change return type of existing function
# HINT:  Use DROP FUNCTION a(integer) first.

DROP FUNCTION a(integer);
# ERROR:  a(integer) is not a function

DROP ROUTINE a(integer);
# DROP ROUTINE

DROP ROUTINE should work for both functions and procedures.
---
 src/backend/catalog/pg_proc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/backend/catalog/pg_proc.c b/src/backend/catalog/pg_proc.c
index 9b4015d0d4..84ee8d686d 100644
--- a/src/backend/catalog/pg_proc.c
+++ b/src/backend/catalog/pg_proc.c
@@ -409,7 +409,7 @@ ProcedureCreate(const char *procedureName,
             ereport(ERROR,
                     (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
                      errmsg("cannot change return type of existing function"),
-                     errhint("Use DROP FUNCTION %s first.",
+                     errhint("Use DROP ROUTINE %s first.",
                              format_procedure(HeapTupleGetOid(oldtup)))));
 
         /*
@@ -434,7 +434,7 @@ 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 ROUTINE %s first.",
                                  format_procedure(HeapTupleGetOid(oldtup)))));
         }
 
@@ -477,7 +477,7 @@ 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 ROUTINE %s first.",
                                      format_procedure(HeapTupleGetOid(oldtup)))));
             }
         }
@@ -501,7 +501,7 @@ 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 ROUTINE %s first.",
                                  format_procedure(HeapTupleGetOid(oldtup)))));
 
             proargdefaults = SysCacheGetAttr(PROCNAMEARGSNSP, oldtup,
@@ -527,7 +527,7 @@ 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 ROUTINE %s first.",
                                      format_procedure(HeapTupleGetOid(oldtup)))));
                 newlc = lnext(newlc);
             }
-- 
2.17.1



pgsql-hackers by date:

Previous
From: Nico Williams
Date:
Subject: Re: [PATCH v18] GSSAPI encryption support
Next
From: Tomas Vondra
Date:
Subject: Re: Standby trying "restore_command" before local WAL