pg_get_triggerdef()

A function for generating a trigger definition

pg_get_triggerdef() is a system function system function which generates the SQL required to recreate the specified trigger.

pg_get_triggerdef() was added in PostgreSQL 7.4.

Usage

pg_get_triggerdef ( trigger oid [, pretty boolean ] ) → text

Note that the returned text is reconstructed from metadata and is not the verbatim text of the original CREATE TRIGGER command.

Change history

Examples

Basic usage example for pg_get_triggerdef():

postgres=# SELECT pg_get_triggerdef(oid)
             FROM pg_trigger
            WHERE tgname = 'trg_foo_01';
                                        pg_get_triggerdef                                         
--------------------------------------------------------------------------------------------------
 CREATE TRIGGER trg_foo_01 AFTER INSERT ON public.foo FOR EACH ROW EXECUTE FUNCTION foo_trigger()
(1 row)

With the pretty option specified:

postgres=# SELECT pg_get_triggerdef(oid, true)
             FROM pg_trigger
            WHERE tgname = 'trg_foo_01';
                                     pg_get_triggerdef                                     
-------------------------------------------------------------------------------------------
 CREATE TRIGGER trg_foo_01 AFTER INSERT ON foo FOR EACH ROW EXECUTE FUNCTION foo_trigger()
(1 row)

Categories

System function, Trigger