|
pg_get_functiondef(func_oid)
text
- get definition of a function
+ get definition of a function or procedure
|
pg_get_function_arguments(func_oid)
text
- get argument list of function's definition (with default values)
+ get argument list of function's or procedure's definition (with default values)
|
pg_get_function_identity_arguments(func_oid)
text
- get argument list to identify a function (without default values)
+ get argument list to identify a function or procedure (without default values)
|
pg_get_function_result(func_oid)
text
- get RETURNS clause for function
+ get RETURNS clause for function (returns null for a procedure)
|
pg_get_indexdef(index_oid)
- This command fetches and edits the definition of the named function,
- in the form of a CREATE OR REPLACE FUNCTION command.
+ This command fetches and edits the definition of the named function or procedure,
+ in the form of a CREATE OR REPLACE FUNCTION or
+ CREATE OR REPLACE PROCEDURE command.
Editing is done in the same way as for \edit.
After the editor exits, the updated command waits in the query buffer;
type semicolon or \g to send it, or \r
- This command fetches and shows the definition of the named function,
- in the form of a CREATE OR REPLACE FUNCTION command.
+ This command fetches and shows the definition of the named function or procedure,
+ in the form of a CREATE OR REPLACE FUNCTION or
+ CREATE OR REPLACE PROCEDURE command.
The definition is printed to the current query output channel,
as set by \o.
StringInfoData dq;
HeapTuple proctup;
Form_pg_proc proc;
+ bool isfunction;
Datum tmp;
bool isnull;
const char *prosrc;
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("\"%s\" is an aggregate function", name)));
+ isfunction = (proc->prorettype != InvalidOid);
+
/*
* We always qualify the function name, to ensure the right function gets
* replaced.
*/
nsp = get_namespace_name(proc->pronamespace);
- appendStringInfo(&buf, "CREATE OR REPLACE FUNCTION %s(",
+ appendStringInfo(&buf, "CREATE OR REPLACE %s %s(",
+ isfunction ? "FUNCTION" : "PROCEDURE",
quote_qualified_identifier(nsp, name));
(void) print_function_arguments(&buf, proctup, false, true);
- appendStringInfoString(&buf, ")\n RETURNS ");
- print_function_rettype(&buf, proctup);
+ appendStringInfoString(&buf, ")\n");
+ if (isfunction)
+ {
+ appendStringInfoString(&buf, " RETURNS ");
+ print_function_rettype(&buf, proctup);
+ appendStringInfoChar(&buf, '\n');
+ }
print_function_trftypes(&buf, proctup);
- appendStringInfo(&buf, "\n LANGUAGE %s\n",
+ appendStringInfo(&buf, " LANGUAGE %s\n",
quote_identifier(get_language_name(proc->prolang, false)));
/* Emit some miscellaneous options on one line */
*
* 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.
+ * with. Hence prefer "$function$"/"$procedure$", but extend if needed.
*/
initStringInfo(&dq);
- appendStringInfoString(&dq, "$function");
+ appendStringInfoChar(&dq, '$');
+ appendStringInfoString(&dq, (isfunction ? "function" : "procedure"));
while (strstr(prosrc, dq.data) != NULL)
appendStringInfoChar(&dq, 'x');
appendStringInfoChar(&dq, '$');