Re: Stamping rows...

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Greg Sabino Mullane <greg(at)turnstep(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org, dicroce(at)pelco(dot)com
Subject: Re: Stamping rows...
Date: 2004-11-23 02:43:29
Message-ID: 20041123024329.GA22271@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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/

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message mariabreis 2004-11-23 12:46:00 Synchronize 2 postgres db
Previous Message Greg Sabino Mullane 2004-11-23 02:14:52 Re: Stamping rows...