From: Charles Clavadetscher <clavadetscher@swisspug.org>
To: Sonam Sharma <sonams1209@gmail.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: Trigger
Date: Fri, 11 Oct 2019 14:00:35 +0200
Message-ID: <80fc8c35849c0ca641ed838c29e4e76e@swisspug.org> (raw)
In-Reply-To: <CAM-M3TkO=CdyDdohXjGT4eixwN5S+MbY1cCaoX1D=mw6sRzfZg@mail.gmail.com>
References: <CAM-M3TkO=CdyDdohXjGT4eixwN5S+MbY1cCaoX1D=mw6sRzfZg@mail.gmail.com>
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 |
| |
+---------------------------+
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: clavadetscher@swisspug.org, sonams1209@gmail.com
Subject: Re: Trigger
In-Reply-To: <80fc8c35849c0ca641ed838c29e4e76e@swisspug.org>
References: <CAM-M3TkO=CdyDdohXjGT4eixwN5S+MbY1cCaoX1D=mw6sRzfZg@mail.gmail.com> <80fc8c35849c0ca641ed838c29e4e76e@swisspug.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox