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




---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to [EMAIL PROTECTED])

Reply via email to