Re: [SQL] Adding a rule to update a last_changed field - Mailing list pgsql-sql

From Brook Milligan
Subject Re: [SQL] Adding a rule to update a last_changed field
Date
Msg-id 199910221536.JAA04682@biology.nmsu.edu
Whole thread Raw
In response to Adding a rule to update a last_changed field  (grant@intekom.com)
List pgsql-sql
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 SETlast_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.

Cheers,
Brook


pgsql-sql by date:

Previous
From: grant@intekom.com
Date:
Subject: Adding a rule to update a last_changed field
Next
From: Tom Lane
Date:
Subject: Re: [SQL] Adding a rule to update a last_changed field