How to get the trigger(s) associated with a view or a table in PostgreSQL

前端 未结 5 767
萌比男神i
萌比男神i 2021-02-01 12:27

I have one requirement that I have to get the list of triggers associated to the given table/view.
Can anyone help me to find the triggers for a table in PostgreSQL?

5条回答
  •  一向
    一向 (楼主)
    2021-02-01 13:10

    This will return all the details you want to know

    select * from information_schema.triggers
    

    or if you want to sort the results of a specific table then you can try

    SELECT event_object_table
          ,trigger_name
          ,event_manipulation
          ,action_statement
          ,action_timing
    FROM  information_schema.triggers
    WHERE event_object_table = 'tableName' -- Your table name comes here
    ORDER BY event_object_table
         ,event_manipulation
    

    the following will return table name that has trigger

    select relname as table_with_trigger
    from pg_class
    where pg_class.oid in (
            select tgrelid
            from pg_trigger
            )
    

提交回复
热议问题