Re: BEFORE UPDATE Triggers

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Chris Anderson <cva(at)pobox(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: BEFORE UPDATE Triggers
Date: 2003-09-01 02:12:02
Message-ID: 3F52AAF2.2000104@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tom Lane wrote:
> Jan Wieck <jan(at)black-lion(dot)info> writes:
>> Unfortunately, you're right. There is no way do distinguish in a trigger
>> or rule if a value in the new row did result from the UPDATE query or
>> from target list expansion with OLD values.
>
>> It would not be terribly hard to examine the original query during
>> executor start, looking for bare OLD referencing Var nodes, and stick
>> something like a flag array into the trigger information.
>
> People keep suggesting this, but I've never thought it was a very sane
> idea. What if some BEFORE trigger upstream of yours changes the column?
> You won't find that out unless you actually compare the OLD and NEW
> column values. If you assume the column has not changed just because
> the original query text didn't change it, you are in for a world of hurt.

That's exactly why I allways ask to look at it from a business process
point of view. The NEW data that will be persistent when the transaction
commits has to match the new status of the business process. Where this
data exactly is coming from, got manipulated or how it got there is not
really relevant. What counts is that the system transforms from one
consistent state into another in an ACID transaction.

Jan

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jomon Skariah 2003-09-01 13:47:43 MINUS & ROWNUM in PostGres
Previous Message Dan Langille 2003-08-31 01:16:26 Re: Getting the return type right for SETOF