Thread: Trigger

Trigger

From
Sonam Sharma
Date:
Can someone please help me in how to list all the triggers with their respective tables and the trigger body

Re: Trigger

From
Charles Clavadetscher
Date:
Hello

On 2019-10-11 12:59, Sonam Sharma wrote:
> Can someone please help me in how to list all the triggers with their
> respective tables and the trigger body

You can use the catalogs:

SELECT t.tgname, t.tgrelid::regclass, t.tgfoid::regprocedure as 
function_name, pg_get_functiondef(t.tgfoid) as function_body FROM 
pg_trigger t WHERE NOT tgisinternal;

There is additional information in the table such as when the trigger 
fire, etc.
Have a look at: 
https://www.postgresql.org/docs/12/catalog-pg-trigger.html

Another way is querying the information schema:

SELECT * FROM information_schema.triggers;

https://www.postgresql.org/docs/12/infoschema-triggers.html
However you won't get there the function body.

Regards
Charles

-- 
Charles Clavadetscher
Swiss PostgreSQL Users Group
Treasurer
Spitzackerstrasse 9
CH - 8057 Zürich

http://www.swisspug.org

+---------------------------+
|     ____  ______  ___     |
|    /    )/      \/   \    |
|   (     / __    _\    )   |
|    \    (/ o)  ( o)   )   |
|     \_  (_  )   \ ) _/    |
|       \  /\_/    \)/      |
|        \/ <//|  |\\>      |
|             _|  |         |
|             \|_/          |
|                           |
|     Swiss PostgreSQL      |
|       Users Group         |
|                           |
+---------------------------+