Thread: Complete instruction in a trigger

Complete instruction in a trigger

From
Wilton
Date:
Hi...
People, i wanna know how can i know inside of a function whar the 
trigger called, i mean which instruction SQL it called.

I do not wanna know if it´s a insert, update or delete (tp_op), i need 
to know the complete instruction.

For example, i need to know something like this:

update phones set number = '9999-2222';

Do you know if maybe exists a tg_stantement?

Thanks very much... see ya


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.4 - Release Date: 25/1/2005



Re: Complete instruction in a trigger

From
Richard Huxton
Date:
Wilton wrote:
> Hi...
> 
> People, i wanna know how can i know inside of a function whar the 
> trigger called, i mean which instruction SQL it called.
> 
> I do not wanna know if it´s a insert, update or delete (tp_op), i need 
> to know the complete instruction.
> 
> For example, i need to know something like this:
> 
> update phones set number = '9999-2222';
> 
> Do you know if maybe exists a tg_stantement?

No, and the situation isn't quite as simple as that. Think about 
foreign-keys with a cascading update.

What precisely are you trying to do?
--  Richard Huxton  Archonet Ltd


Re: Complete instruction in a trigger

From
Wilton
Date:
Sorry if i´m sendind this question to the wrong place... it´s because i´m new here and i didn´t found the place in the web to send my question over the same that i already did.

But let´s see if you can help me. The situation is like this.

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.

Thanks very much.

Wilton Ruffato Wonrath

Re: Complete instruction in a trigger

From
Tom Lane
Date:
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