pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Grant Kaufmann <grant@intekom.com>
To: pgsql-sql@postgresql.org
Subject: Re: [SQL] Adding a rule to update a last_changed field
Date: Fri, 22 Oct 1999 12:05:37 -0400
Message-ID: <19991022120537.A5228@intekom.com> (raw)

This does not work, as it still calls a new UPDATE and re-invokes the rule.


> >   I'm trying to use a rule to maintain a last_changed field. 
> >
> >   CREATE RULE rule1 AS
> >     ON UPDATE TO thetable
> >     DO UPDATE thetable SET last_changed = now()
> >     WHERE id = new.id;
> 
> Try instead something like
> 
>    CREATE RULE rule1 AS
>      ON UPDATE TO thetable
>      DO INSTEAD UPDATE thetable SET
> 	last_changed = now(),
> 	field1 = new.field1,
> 	field2 = new.field2,
> 	...
> 	fieldn = new.fieldn
>      WHERE id = new.id;
> 
> That is, use an INSTEAD rule and replace each field explicitly.





view thread (7+ messages)  latest in thread

Message-ID: <19991022120537.A5228@intekom.com>
Permalink:  ../19991022120537.A5228@intekom.com/
Also on:    postgresql.org/message-id/19991022120537.A5228@intekom.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: grant@intekom.com
  Subject: Re: [SQL] Adding a rule to update a last_changed field
  In-Reply-To: <19991022120537.A5228@intekom.com>
  References: <19991022120537.A5228@intekom.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