X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 11F033A3B39 for ; Tue, 23 Nov 2004 02:15:06 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62424-10 for ; Tue, 23 Nov 2004 02:14:49 +0000 (GMT) Received: from biglumber.com (biglumber.com [207.228.252.42]) by svr1.postgresql.org (Postfix) with SMTP id 1F6B63A3B32 for ; Tue, 23 Nov 2004 02:14:51 +0000 (GMT) Received: (qmail 17366 invoked from network); 23 Nov 2004 02:14:52 -0000 Received: from unknown (HELO localhost) (207.228.252.42) by 0 with SMTP; 23 Nov 2004 02:14:52 -0000 From: "Greg Sabino Mullane" To: pgsql-admin@postgresql.org Cc: dicroce@pelco.com Cc: dicroce@pelco.com Subject: Re: Stamping rows... X-PGP-Key: 2529 DF6A B8F7 9407 E944 45B4 BC9B 9067 1496 4AC8 X-Request-PGP: http://www.biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 In-Reply-To: Date: Tue, 23 Nov 2004 02:14:52 -0000 X-Mailer: JoyMail 1.48 Message-ID: <20d7d6be8697b20a7ba8a1b09cbff757@biglumber.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200411/167 X-Sequence-Number: 15551 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 > I am trying to find a way to stamp all of the rows affected by > an update (or insert) with a unique value. For example, consider > the following table: ... > At first I tried to do this as a trigger function. You were on the right path: ALTER TABLE people ADD mtime TIMESTAMPTZ NOT NULL DEFAULT now(); 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. Unless you mess with your system clock. :) As a nice bonus, you also get to see *when* each row was modified. - -- Greg Sabino Mullane greg@turnstep.com PGP Key: 0x14964AC8 200411222111 -----BEGIN PGP SIGNATURE----- iD8DBQFBop11vJuQZxSWSsgRAuioAKDoVJjASMy0IYQ/T8mO76GEJKQdHQCg2KY7 13ul0+pLO+vEBEjGorUYiIA= =rQnL -----END PGP SIGNATURE-----