Re: defaults on updates - Mailing list pgsql-sql

From Tom Lane
Subject Re: defaults on updates
Date
Msg-id 24956.1067700289@sss.pgh.pa.us
Whole thread Raw
In response to defaults on updates  (Martin Marques <martin@bugs.unl.edu.ar>)
List pgsql-sql
Martin Marques <martin@bugs.unl.edu.ar> writes:
> Basically, I have 5 fields, one being a PK (SERIAL), 3 with information, and 
> the last one a timestamp field that will show the last time the register was 
> modified (tmodif which has a DEFAULT CURRENT_TIMESTAMP).

> Now, eveytime someone modifys any, or all of the 3 information fields,
> I want the tmodif field of that register to be set to now().

This is trivial to do with a trigger --- you just need something like
NEW.lastmod := now();RETURN NEW;

There's a complete example at the bottom of this page:
http://developer.postgresql.org/docs/postgres/plpgsql-trigger.html
        regards, tom lane


pgsql-sql by date:

Previous
From: Martin Marques
Date:
Subject: defaults on updates
Next
From: George Essig
Date:
Subject: Re: connectby