On Tue, Nov 23, 2004 at 02:14:52AM -0000, Greg Sabino Mullane wrote: > CREATE OR REPLACE FUNCTION update_mtime() RETURNS TRIGGER LANGUAGE PLPGSQL AS > 'BEGIN NEW.mtime = now(); RETURN NEW; END;'; > > CREATE TRIGGER people_update_mtime BEFORE UPDATE ON people > FOR EACH ROW EXECUTE PROCEDURE update_mtime(); > > (I use a version of this for my incremental backup scheme) > > Now every update (or insert) will cause all the rows changed to have the > same unique value.
Since now() doesn't advance during a transaction, every other update or insert in the same transaction will get the same "unique" value even if they were performed as separate statements; that may or may not meet the requirements for uniqueness. It also assumes that no two transactions will ever start at exactly the same time. -- Michael Fuhr http://www.fuhr.org/~mfuhr/ ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org
