pg_get_functiondef()

A function generating the SQL for recreating a function or a procedure

pg_get_functiondef() is a system function for generating the SQL command for creating the specified function or procedure.

pg_get_functiondef() was added in PostgreSQL 8.4.

Usage

pg_get_functiondef ( oid ) → text 

Change history

Examples

Basic usage example for pg_get_functiondef():

postgres=# CREATE FUNCTION foo() RETURNS INT LANGUAGE SQL AS 'SELECT 1';
CREATE FUNCTION

postgres=# SELECT pg_get_functiondef('foo()'::regprocedure);
           pg_get_functiondef            
-----------------------------------------
 CREATE OR REPLACE FUNCTION public.foo()+
  RETURNS integer                       +
  LANGUAGE sql                          +
 AS $function$SELECT 1$function$        +
 
(1 row)

pg_get_functiondef() is also used for procedures:

postgres=# CREATE PROCEDURE bar() LANGUAGE SQL AS 'SELECT pg_reload_conf()';
CREATE PROCEDURE

postgres=# SELECT pg_get_functiondef('bar()'::regprocedure);
                pg_get_functiondef                
--------------------------------------------------
 CREATE OR REPLACE PROCEDURE public.bar()        +
  LANGUAGE sql                                   +
 AS $procedure$SELECT pg_reload_conf()$procedure$+
 
(1 row)

Categories

Functions and procedures, System catalogue, System function

See also

pg_get_function_arguments(), pg_get_function_identity_arguments(), pg_get_function_result(),