Fix hints on CREATE PROCEDURE errors

From: Jeremy Evans <code(at)jeremyevans(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Fix hints on CREATE PROCEDURE errors
Date: 2018-08-06 18:32:05
Message-ID: 20180806183205.GB42466@jeremyevans.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)jeremyevans(dot)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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tomas Vondra 2018-08-06 18:47:50 Re: Standby trying "restore_command" before local WAL
Previous Message Nico Williams 2018-08-06 18:26:55 Re: [PATCH v18] GSSAPI encryption support