pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Martin Marques <martin@bugs.unl.edu.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: defaults on updates
Date: Sat, 01 Nov 2003 10:24:49 -0500
Message-ID: <24956.1067700289@sss.pgh.pa.us> (raw)
In-Reply-To: <200311011049.17325.martin@bugs.unl.edu.ar>
References: <200311011049.17325.martin@bugs.unl.edu.ar>

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



view thread (2+ messages)

Message-ID: <24956.1067700289@sss.pgh.pa.us>
Permalink:  ../24956.1067700289@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24956.1067700289@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, martin@bugs.unl.edu.ar
  Subject: Re: defaults on updates
  In-Reply-To: <24956.1067700289@sss.pgh.pa.us>

* 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