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

Re: Stamping rows...

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "Di Croce, Tony" <tdicroce(at)pelco(dot)com>
Cc: "'pgsql-admin(at)postgresql(dot)org'" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Stamping rows...
Date: 2004-11-22 01:56:12
Message-ID: 20041122015612.GA42649@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-admin
On Thu, Nov 18, 2004 at 04:23:50PM -0800, Di Croce, Tony wrote:
> I am trying to find a way to stamp all of the rows affected by an update (or
> insert) with a unique value.

[snip]

> At first I tried to do this as a trigger function. The problem with this
> solution is that if I dont have the function called for each row, I cannot
> modify those rows. if I DO have the function called for each row, how do
> they get the "change_number" they cannot simply call nextval() as it will be
> different for each row (they also couldn't call curval() because then who is
> ever calling nextval()?)

Have you tried calling nextval() in a FOR EACH STATEMENT trigger
and currval() in a FOR EACH ROW trigger?  This works for me in
simple tests.  I don't know if statement triggers are guaranteed
to fire before row triggers, but they do appear to work that way.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

pgsql-admin by date

Next:From: Chris HooverDate: 2004-11-22 18:48:31
Subject: URGENT - HELP WITH 7.3.4 Strangeness
Previous:From: Michael FuhrDate: 2004-11-21 08:43:41
Subject: Re: error loading data with copy

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