summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-09-06 20:18:08 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-09-06 20:18:08 +0000
commit409c144d8343f7f2284ff90979edfec3c487e9ee (patch)
tree015031d47fb926eb2f4a9a7998cf005a564a33d1 /src/backend/utils/adt/ruleutils.c
parent2c863ca818ba0a9704dbfe24eb578870b54bfee8 (diff)
downloadpostgresql-409c144d8343f7f2284ff90979edfec3c487e9ee.tar.gz
Adjust psql's new \ef command to present an empty CREATE FUNCTION template
for editing if no function name is specified. This seems a much cleaner way to offer that functionality than the original patch had. In passing, de-clutter the error displays that are given for a bogus function-name argument, and standardize on "$function$" as the default delimiter for the function body. (The original coding would use the shortest possible dollar-quote delimiter, which seems to create unnecessarily high risk of later conflicts with the user-modified function body.)
Diffstat (limited to 'src/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 07c39fefda..71fea45ddd 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.283 2008/09/06 00:01:21 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.284 2008/09/06 20:18:08 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1543,9 +1543,15 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
elog(ERROR, "null prosrc");
prosrc = TextDatumGetCString(tmp);
- /* We always use dollar quoting. Figure out a suitable delimiter. */
+ /*
+ * We always use dollar quoting. Figure out a suitable delimiter.
+ *
+ * Since the user is likely to be editing the function body string,
+ * we shouldn't use a short delimiter that he might easily create a
+ * conflict with. Hence prefer "$function$", but extend if needed.
+ */
initStringInfo(&dq);
- appendStringInfoChar(&dq, '$');
+ appendStringInfoString(&dq, "$function");
while (strstr(prosrc, dq.data) != NULL)
appendStringInfoChar(&dq, 'x');
appendStringInfoChar(&dq, '$');