pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Wilton <wilton.wonrath@microwork.inf.br>
Cc: pgsql-sql@postgresql.org
Subject: Re: Complete instruction in a trigger
Date: Thu, 27 Jan 2005 10:06:32 -0500
Message-ID: <19794.1106838392@sss.pgh.pa.us> (raw)
In-Reply-To: <41F8F477.7090100@microwork.inf.br>
References: <41F8F477.7090100@microwork.inf.br>

Wilton <wilton.wonrath@microwork.inf.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



view thread (4+ messages)

Message-ID: <19794.1106838392@sss.pgh.pa.us>
Permalink:  ../19794.1106838392@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/19794.1106838392@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, wilton.wonrath@microwork.inf.br
  Subject: Re: Complete instruction in a trigger
  In-Reply-To: <19794.1106838392@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox