pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brook Milligan <brook@biology.nmsu.edu>
To: grant@intekom.com
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Adding a rule to update a last_changed field
Date: Fri, 22 Oct 1999 10:41:18 -0600 (MDT)
Message-ID: <199910221641.KAA04832@biology.nmsu.edu> (raw)
In-Reply-To: <19991022120537.A5228@intekom.com>
References: <19991022120537.A5228@intekom.com>

Oops.

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

You are right.  Your initial mention of using rules made me think of
all the cases I have used this technique for with views.  I forgot
that the two tables are the same.  What I meant to suggest (which may
not be relevant if you really have only one table) was create a rule
for a view of your table that will update the last_changed field in
the underlying table.  I have found that to be very useful in a bunch
of situations where I commonly have one table with lots of different
views and different ways of inserting/deleting/updating as appropriate
to each view.  Then the redirection via an INSTEAD rule and setting
last_* fields with rules is valuable.

Sorry about missing the fact that both of your tables were the same.

   >    CREATE RULE rule1 AS
   >      ON UPDATE TO thetable			<-- for views these are
   >      DO INSTEAD UPDATE thetable SET	<-- not the same table
   > 	last_changed = now(),
   > 	field1 = new.field1,
   > 	field2 = new.field2,
   > 	...
   > 	fieldn = new.fieldn
   >      WHERE id = new.id;

Cheers,
Brook



view thread (7+ messages)  latest in thread

Message-ID: <199910221641.KAA04832@biology.nmsu.edu>
Permalink:  ../199910221641.KAA04832@biology.nmsu.edu/
Also on:    postgresql.org/message-id/199910221641.KAA04832@biology.nmsu.edu

 · 

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: brook@biology.nmsu.edu, grant@intekom.com
  Subject: Re: [SQL] Adding a rule to update a last_changed field
  In-Reply-To: <199910221641.KAA04832@biology.nmsu.edu>
  References: <19991022120537.A5228@intekom.com> <199910221641.KAA04832@biology.nmsu.edu>

* 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