Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-admin by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group