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

前端 未结 5 777
萌比男神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:15

    The problem with the view information_schema.triggers (besides being slow) is, per documentation:

    The view triggers contains all triggers defined in the current database on tables and views that the current user owns or has some privilege other than SELECT on.

    Meaning, you only get to see triggers you have appropriate privileges on.

    To see all triggers for a table, look in the system catalog pg_trigger

    SELECT tgname
    FROM   pg_trigger
    WHERE  tgrelid = 'myschema.mytbl'::regclass; -- optionally schema-qualified
    

    Works for tables and views.
    Or you could use a GUI like pgAdmin that displays the list under the table node in the object browser.

提交回复
热议问题