HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

PostgreSQL: how do I list all triggers that use a specific field?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
postgresqlfieldallthathowlistusetriggersspecific

Problem

for example i have a student table with (studentid)
i want to get a list of triggers that use this field...

for example if in table X there is a trigger that uses studentid i want it to be shown in the query result.

Solution

If you want to filter on the tablle name if you have too many triggers just add a filter on relname from pg_class

SELECT tgrelid::regclass,t.tgname FROM pg_trigger t, pg_proc p, pg_class c 
WHERE c.oid = t.tgrelid AND t.tgfoid=p.oid 
AND c.relkind = 'r'
AND p.prosrc LIKE '%studentid%' AND c.relname = 'X';

Code Snippets

SELECT tgrelid::regclass,t.tgname FROM pg_trigger t, pg_proc p, pg_class c 
WHERE c.oid = t.tgrelid AND t.tgfoid=p.oid 
AND c.relkind = 'r'
AND p.prosrc LIKE '%studentid%' AND c.relname = 'X';

Context

StackExchange Database Administrators Q#103126, answer score: 2

Revisions (0)

No revisions yet.