Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have a trigger in PostgreSql 9.1 that i want to fire on inserts of several tables. is it possible to have it affect all these tables instead of creating the trigger for all these tables? i have 58 tables that i want to use the same insert trigger which is calling a trigger function, so i have been using

create trigger tuweke 
after insert on product 
for each row execute procedure tuwekeAdjustextract(); 
create trigger tuweke 
after insert on caneweightment 
for each row execute procedure tuwekeAdjustextract(); 

doing this for all those tables and then we have multiple schemas,so the workload is alot,can this be done in one query? then affect all tables in that schema or the whole database?

share|improve this question
I suppose not. What did you try? – Nitesh Verma Jan 30 '13 at 9:04
@Nitesh i have edited my question – indago Jan 30 '13 at 9:29
up vote 4 down vote accepted

There is no option like that. A trigger belongs to a table and that is that. However, if all your triggers use the same procedure, you can easily generate a nice text output with all the CREATE TRIGGER statements. The only thing to do is to collect the desired table names and then prepend and appent the necessary parts to those.

You can get all table names from a given schema with a query like this:

SELECT p.tablename
FROM pg_tables p
WHERE p.schemaname = 'public'

If now you select

AFTER INSERT ON ' || p.tablename || '

instead of p.tablename then you are ready. Copy the output and run it.

share|improve this answer
thanks for you answer,how can i implement the output? i need help in implementing this. All this triggers will be calling the same trigger function. – indago Jan 30 '13 at 9:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.