@@ -2449,6 +2449,7 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
24492449 StringInfoData dq ;
24502450 HeapTuple proctup ;
24512451 Form_pg_proc proc ;
2452+ bool isfunction ;
24522453 Datum tmp ;
24532454 bool isnull ;
24542455 const char * prosrc ;
@@ -2472,20 +2473,28 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
24722473 (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
24732474 errmsg ("\"%s\" is an aggregate function" , name )));
24742475
2476+ isfunction = (proc -> prorettype != InvalidOid );
2477+
24752478 /*
24762479 * We always qualify the function name, to ensure the right function gets
24772480 * replaced.
24782481 */
24792482 nsp = get_namespace_name (proc -> pronamespace );
2480- appendStringInfo (& buf , "CREATE OR REPLACE FUNCTION %s(" ,
2483+ appendStringInfo (& buf , "CREATE OR REPLACE %s %s(" ,
2484+ isfunction ? "FUNCTION" : "PROCEDURE" ,
24812485 quote_qualified_identifier (nsp , name ));
24822486 (void ) print_function_arguments (& buf , proctup , false, true);
2483- appendStringInfoString (& buf , ")\n RETURNS " );
2484- print_function_rettype (& buf , proctup );
2487+ appendStringInfoString (& buf , ")\n" );
2488+ if (isfunction )
2489+ {
2490+ appendStringInfoString (& buf , " RETURNS " );
2491+ print_function_rettype (& buf , proctup );
2492+ appendStringInfoChar (& buf , '\n' );
2493+ }
24852494
24862495 print_function_trftypes (& buf , proctup );
24872496
2488- appendStringInfo (& buf , "\n LANGUAGE %s\n" ,
2497+ appendStringInfo (& buf , " LANGUAGE %s\n" ,
24892498 quote_identifier (get_language_name (proc -> prolang , false)));
24902499
24912500 /* Emit some miscellaneous options on one line */
@@ -2607,10 +2616,11 @@ pg_get_functiondef(PG_FUNCTION_ARGS)
26072616 *
26082617 * Since the user is likely to be editing the function body string, we
26092618 * shouldn't use a short delimiter that he might easily create a conflict
2610- * with. Hence prefer "$function$", but extend if needed.
2619+ * with. Hence prefer "$function$"/"$procedure$" , but extend if needed.
26112620 */
26122621 initStringInfo (& dq );
2613- appendStringInfoString (& dq , "$function" );
2622+ appendStringInfoChar (& dq , '$' );
2623+ appendStringInfoString (& dq , (isfunction ? "function" : "procedure" ));
26142624 while (strstr (prosrc , dq .data ) != NULL )
26152625 appendStringInfoChar (& dq , 'x' );
26162626 appendStringInfoChar (& dq , '$' );
0 commit comments