Coming from Oracle - trigger question

From: "Graeme Merrall" <gbmerrall(at)aol(dot)com>
To: "Pgsql-General" <pgsql-general(at)postgresql(dot)org>
Subject: Coming from Oracle - trigger question
Date: 2002-06-20 06:44:07
Message-ID: NNEKJJAGMOPDHMDJNLBJCELKCBAA.GBMerrall@aol.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'm mucking about playing with triggers and functions and in Oracle it's
possible to check that a trigger isn't actually acting on a field you want
to update.
The function below will update the 'dirty' column as long as you're not
performing an operation on the 'dirty' as part of your SQL statement

CREATE OR REPLACE TRIGGER before_nodes_update
before update on nodes
for each row
begin
if not updating('DIRTY') then
:new.dirty := 1;
:new.modified := sysdate;
end if;
end;

Hence, "UPDATE nodes SET text='updating' WHERE node=1" would fire the
trigger and "UPDATE nodes SET dirty=0 WHERE node=1" would not fire the
trigger since we're updating the dirty column in the query.

Now I'm after the same functionality in postgres. Is there a way around
this? I have a feeling that rules my acheive what I'm after but it seems a
bit overkill for a simple column update.

Cheers,
Graeme

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Henrik Steffen 2002-06-20 06:53:42 Re: Serious Crash last Friday
Previous Message Hiroshi Inoue 2002-06-20 02:48:04 Re: ODBC Error