Re: Complete instruction in a trigger

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Wilton <wilton(dot)wonrath(at)microwork(dot)inf(dot)br>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Complete instruction in a trigger
Date: 2005-01-27 15:06:32
Message-ID: 19794.1106838392@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Wilton <wilton(dot)wonrath(at)microwork(dot)inf(dot)br> writes:
> I have a table "customers", then a user go there and change the customer
> record, for example he changes the zip code column. Then I can know that
> something changed into the "customer table", and send a full update of
> that record through the web to the database that i want, but i need to
> know what column had changed to send a update just for that column. But
> i do not know in which column his has made that change. So, i need to
> know the instruction to do this. Something like a specific update for
> that column modified by the user.

People ask for this often, and in every case I've seen, they would be
wrong to depend on it if they had it. The reason is that the original
SQL query is not sufficient information to tell which columns changed.
Consider for example the possibility that the query was rewritten by a
rule, or the new tuple was modified by another trigger that executed
ahead of yours.

The only correct way to determine which columns changed is to compare
the OLD and NEW values of each column ... and you'd better do it in an
AFTER trigger, not a BEFORE trigger, if you want to be certain that you
are looking at the final result.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sean Davis 2005-01-27 15:07:26 Re: [SQL] URL activation through trigger
Previous Message Joel Fradkin 2005-01-27 14:40:05 Hardware for best performance was same question little different test MSSQL vrs Postgres