pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: Complete instruction in a trigger
4+ messages / 3 participants
[nested] [flat]

* Re: Complete instruction in a trigger
@ 2005-01-27 11:35  Richard Huxton <dev@archonet.com>
  parent: Wilton <wilton.wonrath@microwork.inf.br>
  0 siblings, 0 replies; 4+ messages in thread

From: Richard Huxton @ 2005-01-27 11:35 UTC (permalink / raw)
  To: Wilton <wilton.wonrath@microwork.inf.br>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Complete instruction in a trigger
@ 2005-01-27 12:21  Wilton <wilton.wonrath@microwork.inf.br>
  0 siblings, 1 reply; 4+ messages in thread

From: Wilton @ 2005-01-27 12:21 UTC (permalink / raw)
  To: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Complete instruction in a trigger
@ 2005-01-27 14:02  Wilton <wilton.wonrath@microwork.inf.br>
  0 siblings, 1 reply; 4+ messages in thread

From: Wilton @ 2005-01-27 14:02 UTC (permalink / raw)
  To: pgsql-sql

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
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.6 - Release Date: 27/1/2005

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Complete instruction in a trigger
@ 2005-01-27 15:06  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Wilton <wilton.wonrath@microwork.inf.br>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2005-01-27 15:06 UTC (permalink / raw)
  To: Wilton <wilton.wonrath@microwork.inf.br>; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2005-01-27 15:06 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-27 12:21 Complete instruction in a trigger Wilton <wilton.wonrath@microwork.inf.br>
2005-01-27 11:35 ` Richard Huxton <dev@archonet.com>
2005-01-27 14:02 Re: Complete instruction in a trigger Wilton <wilton.wonrath@microwork.inf.br>
2005-01-27 15:06 ` Tom Lane <tgl@sss.pgh.pa.us>

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