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