Re: Help on Trigger functions

From: Keith Worthington <KeithW(at)NarrowPathInc(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Cc: "Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com>
Subject: Re: Help on Trigger functions
Date: 2005-03-04 15:00:27
Message-ID: 4228780B.3090906@NarrowPathInc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Pradeepkumar, Pyatalo (IE10) wrote:

>
>
> Hi all,
>
> I have a table something like this -
>
> PointTable(PointName varchar, PointType integer, PointValue integer);
>
> I have to write a trigger before UPDATE on this table. In the trigger
> function, I need to check which field of the table is going to be
> updated...based on this I need to do some operation.
>
> CREATE FUNCTION Trg_UpdPointTable RETURNS TRIGGER AS'
> BEGIN
> IF PointType is being modified THEN
> // do some operation.
> ELSIF PointValue is being modified THEN
> // Do some operation
> END IF;
> END;
>
> CREATE TRIGGER PTableTrg BEFORE UPDATE ON PointTable FOR EVERY ROW
> EXECUTE PROCEDURE Trg_UpdPointTable();
>
>
> Is this functionality possible. I am using PostgreSQL version 7.4.3.
>
> Thanks in advance.
>
> Regards,
> Pradeep
>
>
Pradeep,

You can access the before and after values of an update statement with
the NEW and OLD record variables. See
http://www.postgresql.org/docs/8.0/interactive/plpgsql-trigger.html for
more information. Based on that I think that you can do something like:

IF NEW.pointtype <> OLD.pointtype THEN

HTH

--
Kind Regards,
Keith

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Bruno Wolff III 2005-03-04 15:11:46 Re: Import csv file into multiple tables in Postgres
Previous Message Bruno Wolff III 2005-03-04 14:43:33 Re: User right management concerning functions