pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Williams <jeffw@globaldial.com>
To: pgsql-sql@postgresql.org
Subject: Update timestamp on update
Date: Thu, 13 Oct 2005 09:12:34 +0800
Message-ID: <434DB482.1000205@globaldial.com> (raw)

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



view thread (9+ messages)  latest in thread

Message-ID: <434DB482.1000205@globaldial.com>
Permalink:  ../434DB482.1000205@globaldial.com/
Also on:    postgresql.org/message-id/434DB482.1000205@globaldial.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: jeffw@globaldial.com
  Subject: Re: Update timestamp on update
  In-Reply-To: <434DB482.1000205@globaldial.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