Updated on 2022-06-11 GMT+08:00

Trigger Functions

  • pg_get_triggerdef(oid)

    Description: Obtains the definition information of a trigger.

    Parameter: OID of the trigger to be queried

    Return type: text

    Example:

    1
    2
    3
    4
    5
    select pg_get_triggerdef(oid) from pg_trigger;
                                                      pg_get_triggerdef
    ----------------------------------------------------------------------------------------------------------------------
     CREATE TRIGGER insert_trigger BEFORE INSERT ON test_trigger_src_tbl FOR EACH ROW EXECUTE PROCEDURE tri_insert_func()
    (1 row)
    
  • pg_get_triggerdef(oid, boolean)

    Description: Obtains the definition information of a trigger.

    Parameter: OID of the trigger to be queried and whether it is displayed in pretty mode

    Return type: text

    The Boolean parameters take effect only when the WHEN condition is specified during trigger creation.

    Example:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    select pg_get_triggerdef(oid,true)from pg_trigger;
                                                      pg_get_triggerdef
    ----------------------------------------------------------------------------------------------------------------------
     CREATE TRIGGER insert_trigger BEFORE INSERT ON test_trigger_src_tbl FOR EACH ROW EXECUTE PROCEDURE tri_insert_func()
    (1 row)
    
    select pg_get_triggerdef(oid,false)from pg_trigger;
                                                      pg_get_triggerdef
    ----------------------------------------------------------------------------------------------------------------------
     CREATE TRIGGER insert_trigger BEFORE INSERT ON test_trigger_src_tbl FOR EACH ROW EXECUTE PROCEDURE tri_insert_func()
    (1 row)