-- -- Start by creating our table -- richardh=> create table foo (a serial, b text, c timestamp); NOTICE: CREATE TABLE will create implicit sequence 'foo_a_seq' for SERIAL column 'foo.a' NOTICE: CREATE TABLE/UNIQUE will create implicit index 'foo_a_key' for table 'foo' CREATE -- -- Now import the lastchg module (you might want to use the full path) -- richardh=> \i lastchange.sql CREATE CREATE -- -- Create insert/update trigger -- richardh=> select lastchg_addto('foo','c'); lastchg_addto ------------------------- Created lastchg trigger (1 row) -- -- Insert some data -- richardh=> insert into foo (b) values ('aaa'); INSERT 217867 1 richardh=> insert into foo (b) values ('bbb'); INSERT 217868 1 richardh=> insert into foo (b) values ('ccc'); INSERT 217869 1 richardh=> select * from foo; a | b | c ---+-----+------------------------ 1 | aaa | 2001-02-08 09:33:35+00 2 | bbb | 2001-02-08 09:33:38+00 3 | ccc | 2001-02-08 09:33:40+00 (3 rows) -- -- Update some data -- richardh=> update foo set b='xxx'; UPDATE 3 richardh=> select * from foo; a | b | c ---+-----+------------------------ 1 | xxx | 2001-02-08 09:34:41+00 2 | xxx | 2001-02-08 09:34:41+00 3 | xxx | 2001-02-08 09:34:41+00 (3 rows) -- -- Remove the triggers -- richardh=> select lastchg_remove('foo','c'); lastchg_remove ------------------------- Removed lastchg trigger (1 row) -- -- Timestamp shouldn't update now -- richardh=> update foo set b='yyy'; UPDATE 3 richardh=> select * from foo; a | b | c ---+-----+------------------------ 1 | yyy | 2001-02-08 09:34:41+00 2 | yyy | 2001-02-08 09:34:41+00 3 | yyy | 2001-02-08 09:34:41+00 (3 rows)