pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedReg: Firing Trigger when a particular column value get changed
3+ messages / 3 participants
[nested] [flat]
* Reg: Firing Trigger when a particular column value get changed
@ 2003-09-19 11:01 Thilak babu <thilakbabu@siptech.co.in>
0 siblings, 1 reply; 3+ messages in thread
From: Thilak babu @ 2003-09-19 11:01 UTC (permalink / raw)
To: pgsql-sql
Hi All,
I have a scnerio as to fire a trigger when i update a particular column
in a table. Please do help me out in getting thro this.
Thanks in advance,
Thilak
.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Reg: Firing Trigger when a particular column value get changed
@ 2003-09-20 22:38 Kevin Houle <kevin@houle.org>
parent: Thilak babu <thilakbabu@siptech.co.in>
0 siblings, 1 reply; 3+ messages in thread
From: Kevin Houle @ 2003-09-20 22:38 UTC (permalink / raw)
To: Thilak babu <thilakbabu@siptech.co.in>
Thilak babu wrote:
> I have a scnerio as to fire a trigger when i update a particular column
> in a table. Please do help me out in getting thro this.
The trigger function can use logic to exclude cases where a particular
column does not change. For example:
CREATE FUNCTION "column_update" () RETURNS TRIGGER AS '
BEGIN
IF ( NEW.column <> OLD.column ) THEN
do-your-stuff-here;
END IF;
RETURN NEW;
END; ' LANGUAGE 'plpgsql';
CREATE TRIGGER "tg_column_update"
BEFORE UPDATE ON "table_name"
FOR EACH ROW EXECUTE PROCEDURE "column_update" ();
The trigger fires on every update, but the procedure doesn't do
anything unless the particular column changes. I don't think a
trigger can be defined to fire on anything more granular than a
table operation.
Kevin
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Reg: Firing Trigger when a particular column value get changed
@ 2003-09-22 05:21 sad <sad@bankir.ru>
parent: Kevin Houle <kevin@houle.org>
0 siblings, 0 replies; 3+ messages in thread
From: sad @ 2003-09-22 05:21 UTC (permalink / raw)
To: pgsql-sql
On Sunday 21 September 2003 02:38, you wrote:
> Thilak babu wrote:
> > I have a scnerio as to fire a trigger when i update a particular column
> > in a table. Please do help me out in getting thro this.
>
> The trigger function can use logic to exclude cases where a particular
> column does not change. For example:
>
> CREATE FUNCTION "column_update" () RETURNS TRIGGER AS '
> BEGIN
> IF ( NEW.column <> OLD.column ) THEN
> do-your-stuff-here;
> END IF;
> RETURN NEW;
> END; ' LANGUAGE 'plpgsql';
this trigger will not execute "your-stuff-here"
if NEW.column or OLD.column will be null.
you need to add this case to the logic statement in the "IF"
(NEW.column <> OLD.column) OR (NEW.column IS NULL <> OLD.column. IS NULL)
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-09-22 05:21 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-19 11:01 Reg: Firing Trigger when a particular column value get changed Thilak babu <thilakbabu@siptech.co.in>
2003-09-20 22:38 ` Kevin Houle <kevin@houle.org>
2003-09-22 05:21 ` sad <sad@bankir.ru>
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