pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
UPDATE Trigger on multiple tables
3+ messages / 3 participants
[nested] [flat]

* UPDATE Trigger on multiple tables
@ 2005-10-13 04:29  Ferindo Middleton Jr <fmiddleton@verizon.net>
  0 siblings, 2 replies; 3+ messages in thread

From: Ferindo Middleton Jr @ 2005-10-13 04:29 UTC (permalink / raw)
  To: pgsql-sql

Is it possible to have a single trigger on multiple tables 
simultaneously? Example:

CREATE TRIGGER emp_cust_stamp BEFORE INSERT OR UPDATE ON employees, customers
    FOR EACH ROW EXECUTE PROCEDURE last_updated_stamp();

I tried something like the above but get an error message at the comma. I tried using the keyword AND as well. 
I couldn't find anything on this in the docs. I have many different tables in my databases which all have a 
"last_updated" field and it seems less tedious to be able to enforce updating this trigger database-wide using 
just one trigger. Is it possible?

Ferindo





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: UPDATE Trigger on multiple tables
@ 2005-10-13 04:39  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Ferindo Middleton Jr <fmiddleton@verizon.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2005-10-13 04:39 UTC (permalink / raw)
  To: fmiddleton@verizon.net; +Cc: pgsql-sql

Ferindo Middleton Jr <fmiddleton@verizon.net> writes:
> Is it possible to have a single trigger on multiple tables 
> simultaneously? Example:

> CREATE TRIGGER emp_cust_stamp BEFORE INSERT OR UPDATE ON employees, customers
>     FOR EACH ROW EXECUTE PROCEDURE last_updated_stamp();

No.  You can use the same function for multiple triggers, but you have
to CREATE TRIGGER for each table separately.

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: UPDATE Trigger on multiple tables
@ 2005-10-13 13:22  Muralidharan Ramakrishnan <contact2muraliin@yahoo.co.in>
  parent: Ferindo Middleton Jr <fmiddleton@verizon.net>
  1 sibling, 0 replies; 3+ messages in thread

From: Muralidharan Ramakrishnan @ 2005-10-13 13:22 UTC (permalink / raw)
  To: fmiddleton@verizon.net; pgsql-sql

Hi
 
  CREATE TRIGGER associates trigger function on a table and it is not possible to give more than one table seperated by comas.
 
  CREATE TRIGGER emp_cust_stamp BEFORE INSERT OR UPDATE ON  customers
FOR EACH ROW EXECUTE PROCEDURE last_updated_stamp();

CREATE TRIGGER emp_cust_stamp BEFORE INSERT OR UPDATE ON employees
FOR EACH ROW EXECUTE PROCEDURE last_updated_stamp();
 
Regards,
R.Muralidharan


Ferindo Middleton Jr <fmiddleton@verizon.net> wrote:
Is it possible to have a single trigger on multiple tables 
simultaneously? Example:

CREATE TRIGGER emp_cust_stamp BEFORE INSERT OR UPDATE ON employees, customers
FOR EACH ROW EXECUTE PROCEDURE last_updated_stamp();

I tried something like the above but get an error message at the comma. I tried using the keyword AND as well. 
I couldn't find anything on this in the docs. I have many different tables in my databases which all have a 
"last_updated" field and it seems less tedious to be able to enforce updating this trigger database-wide using 
just one trigger. Is it possible?

Ferindo



---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org


		
---------------------------------
 Yahoo! India Matrimony: Find your partner now.

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2005-10-13 13:22 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-10-13 04:29 UPDATE Trigger on multiple tables Ferindo Middleton Jr <fmiddleton@verizon.net>
2005-10-13 04:39 ` Tom Lane <tgl@sss.pgh.pa.us>
2005-10-13 13:22 ` Muralidharan Ramakrishnan <contact2muraliin@yahoo.co.in>

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