pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: chester c young <chestercyoung@yahoo.com>
To: josh@agliodbs.com
To: pgsql-sql@postgresql.org
Subject: Re: Is there any way to stop triggers from cycling?
Date: Wed, 8 Mar 2006 15:04:18 -0800 (PST)
Message-ID: <20060308230419.53923.qmail@web54308.mail.yahoo.com> (raw)
In-Reply-To: <200603081358.25185.josh@agliodbs.com>

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 



view thread (5+ messages)  latest in thread

Message-ID: <20060308230419.53923.qmail@web54308.mail.yahoo.com>
Permalink:  ../20060308230419.53923.qmail@web54308.mail.yahoo.com/
Also on:    postgresql.org/message-id/20060308230419.53923.qmail@web54308.mail.yahoo.com

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: chestercyoung@yahoo.com, josh@agliodbs.com
  Subject: Re: Is there any way to stop triggers from cycling?
  In-Reply-To: <20060308230419.53923.qmail@web54308.mail.yahoo.com>

* 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