From: Greg Sabino Mullane <greg@turnstep.com>
To: pgsql-admin@postgresql.org
Cc: dicroce@pelco.com
Subject: Re: Stamping rows...
Date: Tue, 23 Nov 2004 02:14:52 -0000
Message-ID: <20d7d6be8697b20a7ba8a1b09cbff757@biglumber.com> (raw)
In-Reply-To: <B2CC0E0F2C10D511B86600B0D06898420EA053DE@NETSRVR1.pelco.org>
-----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-----
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: greg@turnstep.com, dicroce@pelco.com
Subject: Re: Stamping rows...
In-Reply-To: <20d7d6be8697b20a7ba8a1b09cbff757@biglumber.com>
References: <B2CC0E0F2C10D511B86600B0D06898420EA053DE@NETSRVR1.pelco.org> <20d7d6be8697b20a7ba8a1b09cbff757@biglumber.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox