From: | chester c young <chestercyoung(at)yahoo(dot)com> |
---|---|
To: | josh(at)agliodbs(dot)com, pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Is there any way to stop triggers from cycling? |
Date: | 2006-03-08 23:04:18 |
Message-ID: | 20060308230419.53923.qmail@web54308.mail.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
trying to do this exlusively in triggers is a forray into folly.
take advantage of "instead of" or "do also" rules to create a compound
statement before your triggers do their work. (in terms of maintenance
and sanity, it's best if a trigger touches only its own record.)
as a handsweep example:
create view tree_v as select * from tree;
grant select, insert, update on tree_v to public;
create or replace rule 'tree_update' as
on update
to tree_v
do instead(
--
update tree set seq = seq+1
where old.pnt=new.pnt and old.seq<new.seq-1
and pnt = old.pnt and seq between old.seq and new.neq;
--
update tree set set = new.seq
where old.pnt=new.pnt and old.seq != new.seq
and pnt = old.pnt and seq = new.seq;
);
note two conditions on the where clause: first is rule when to do it,
and second is what record to do it on.
you might not need the intermediate view, but I always use a view
between my app and the table - for reasons like this and many, many
others.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
From | Date | Subject | |
---|---|---|---|
Next Message | Josh Berkus | 2006-03-08 23:29:09 | Re: Is there any way to stop triggers from cycling? |
Previous Message | Rod Taylor | 2006-03-08 22:35:50 | Re: Is there any way to stop triggers from cycling? |