Re: Touch row ? - Mailing list pgsql-general

From Mike Mascari
Subject Re: Touch row ?
Date
Msg-id 4010EAFD.7050509@mascari.com
Whole thread Raw
In response to Touch row ?  ("NTPT" <ntpt@centrum.cz>)
Responses Re: Touch row ?
Re: Touch row ?
List 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
orUPDATE ? 
>
>

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




pgsql-general by date:

Previous
From: Dustin Sallings
Date:
Subject: Re: Touch row ?
Next
From: Mike Mascari
Date:
Subject: Re: Touch row ?