Re: Touch row ?

From: Mike Mascari <mascarm(at)mascari(dot)com>
To: NTPT <ntpt(at)centrum(dot)cz>
Cc: PostgreSQL-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Touch row ?
Date: 2004-01-23 09:35:57
Message-ID: 4010EAFD.7050509@mascari.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-announce pgsql-general

NTPT wrote:

>is it possible to add column to database,
>
ALTER TABLE foo
ADD COLUMN mod_date TIMESTAMP;

>that will automatically contain date+time (or likely Unix timestamp) when the row was touched/changed - ie by INSERT or UPDATE ?
>
>

CREATE FUNCTION touch() RETURNS trigger AS '
begin
NEW.mod_date = LOCALTIMESTAMP;
return NEW;
end;
' language 'plpgsql';

CREATE TRIGGER t_foo
BEFORE INSERT OR UPDATE ON foo
FOR EACH ROW
EXECUTE PROCEDURE touch();

If you want timezone information, use TIMESTAMP WITH TIME ZONE and
CURRENTTIMESTAMP. These are transaction start times.

HTH,

Mike Mascari

In response to

Responses

Browse pgsql-announce by date

  From Date Subject
Next Message Mike Mascari 2004-01-23 09:42:29 Re: Touch row ?
Previous Message Dustin Sallings 2004-01-23 09:35:52 Re: Touch row ?

Browse pgsql-general by date

  From Date Subject
Next Message Mike Mascari 2004-01-23 09:42:29 Re: Touch row ?
Previous Message Dustin Sallings 2004-01-23 09:35:52 Re: Touch row ?