pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedHow to notice column changes in trigger
4+ messages / 3 participants
[nested] [flat]
* How to notice column changes in trigger
@ 2003-03-06 15:00 Andreas Pflug <Andreas.Pflug@web.de>
2003-03-06 16:01 ` Re: How to notice column changes in trigger Oliver Elphick <olly@lfix.co.uk>
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Pflug @ 2003-03-06 15:00 UTC (permalink / raw)
To: pgsql-performance
How can I detect whether a column was changed by an update command
inside a trigger?
create table test(a int, b int, c int, primary key(a))
b and c should be updated inside an update trigger if not modified by
the statement itself
1) update test set a=0 -> trigger does its work
2) update test set a=0, b=1, c=2 -> trigger does nothing
3) update test set a=0, b=b, c=c -> trigger does nothing, but content of
a and b dont change either although touched
What I'm looking for is something like
IF NOT COLUMN_TOUCHED(b) THEN ...
For MSSQL, this would be coded as IF NOT UPDATE(b) ..
Any hints?
Andreas
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How to notice column changes in trigger
2003-03-06 15:00 How to notice column changes in trigger Andreas Pflug <Andreas.Pflug@web.de>
@ 2003-03-06 16:01 ` Oliver Elphick <olly@lfix.co.uk>
2003-03-06 16:09 ` Re: How to notice column changes in trigger Andreas Pflug <Andreas.Pflug@web.de>
0 siblings, 1 reply; 4+ messages in thread
From: Oliver Elphick @ 2003-03-06 16:01 UTC (permalink / raw)
To: Andreas Pflug <Andreas.Pflug@web.de>; +Cc: pgsql-performance
On Thu, 2003-03-06 at 15:00, Andreas Pflug wrote:
> How can I detect whether a column was changed by an update command
> inside a trigger?
>
> create table test(a int, b int, c int, primary key(a))
>
> b and c should be updated inside an update trigger if not modified by
> the statement itself
>
> 1) update test set a=0 -> trigger does its work
> 2) update test set a=0, b=1, c=2 -> trigger does nothing
> 3) update test set a=0, b=b, c=c -> trigger does nothing, but content of
> a and b dont change either although touched
>
> What I'm looking for is something like
> IF NOT COLUMN_TOUCHED(b) THEN ...
> For MSSQL, this would be coded as IF NOT UPDATE(b) ..
IF NEW.b = OLD.b OR (NEW.b IS NULL AND OLD.b IS NULL) THEN
-- b has not changed
...
END IF;
--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"The LORD is my light and my salvation; whom shall I
fear? the LORD is the strength of my life; of whom
shall I be afraid?" Psalms 27:1
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How to notice column changes in trigger
2003-03-06 15:00 How to notice column changes in trigger Andreas Pflug <Andreas.Pflug@web.de>
2003-03-06 16:01 ` Re: How to notice column changes in trigger Oliver Elphick <olly@lfix.co.uk>
@ 2003-03-06 16:09 ` Andreas Pflug <Andreas.Pflug@web.de>
2003-03-06 17:05 ` Re: How to notice column changes in trigger Josh Berkus <josh@agliodbs.com>
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Pflug @ 2003-03-06 16:09 UTC (permalink / raw)
To: pgsql-performance
Oliver Elphick wrote:
> IF NEW.b = OLD.b OR (NEW.b IS NULL AND OLD.b IS NULL) THEN
> -- b has not changed
> ...
> END IF;
>
>
This doesn't cover case 3, since UPDATE ... SET b=b will lead to NEW.b=OLD.b
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: How to notice column changes in trigger
2003-03-06 15:00 How to notice column changes in trigger Andreas Pflug <Andreas.Pflug@web.de>
2003-03-06 16:01 ` Re: How to notice column changes in trigger Oliver Elphick <olly@lfix.co.uk>
2003-03-06 16:09 ` Re: How to notice column changes in trigger Andreas Pflug <Andreas.Pflug@web.de>
@ 2003-03-06 17:05 ` Josh Berkus <josh@agliodbs.com>
0 siblings, 0 replies; 4+ messages in thread
From: Josh Berkus @ 2003-03-06 17:05 UTC (permalink / raw)
To: Andreas Pflug <Andreas.Pflug@web.de>; pgsql-performance
Andreas,
> This doesn't cover case 3, since UPDATE ... SET b=b will lead to
> NEW.b=OLD.b
Why do you care about SET b = b?
And shouldn't this discussion be on the PGSQL-SQL list?
--
Josh Berkus
Aglio Database Solutions
San Francisco
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2003-03-06 17:05 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-03-06 15:00 How to notice column changes in trigger Andreas Pflug <Andreas.Pflug@web.de>
2003-03-06 16:01 ` Oliver Elphick <olly@lfix.co.uk>
2003-03-06 16:09 ` Andreas Pflug <Andreas.Pflug@web.de>
2003-03-06 17:05 ` Josh Berkus <josh@agliodbs.com>
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