Update timestamp on update - Mailing list pgsql-sql

From Jeff Williams
Subject Update timestamp on update
Date
Msg-id 434DB482.1000205@globaldial.com
Whole thread Raw
Responses Re: Update timestamp on update  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
I have a table like:

CREATE TABLE products (   id int,   status int,   last_status_change timestamp DEFAULT now()
);

What I would like is that whenever the status is changed the
last_status_change timestamp is updated to the current time. I have had
a look at the rules and what I want would be similar to:

CREATE RULE last_status_change AS ON UPDATE   TO products WHERE NEW.status <> OLD.status   DO UPDATE products SET
last_status_change= now() WHERE id = OLD.id;
 

Except of course that the above is recursive and doesn't work.

How can I do this?

Jeff


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Text->Date conversion in a WHERE clause
Next
From: Greg Stark
Date:
Subject: Re: pg, mysql comparison with "group by" clause