Re: Update and trigger - Mailing list pgsql-sql

From Craig Ringer
Subject Re: Update and trigger
Date
Msg-id 484F6424.5040202@postnewspapers.com.au
Whole thread Raw
In response to Update and trigger  ("Medi Montaseri" <montaseri@gmail.com>)
List pgsql-sql
Medi Montaseri wrote:
> Hi,
> 
> I need to increament a counter such as myTable.Counter of type integer 
> everytime myTable.status a boolean column is updated. Can you help me 
> complete this...
> 
> create trigger counter_trigger after update on myTable.counter
> execute procedure 'BEGIN statement; statement; statement END'
> 
> Q1- how do I narrow the event to "update on a column not a row"

Use a row-level trigger and test to see if the column of interest has 
been altered. Eg:

IF new.fieldname IS DISTINCT FROM old.fieldname THEN   -- Do the work
END IF;

> Q2- can I just provide an inline procedure for the execute

No, at present you must create a function that returns TRIGGER and then 
use that as the target to execute. At least as far as I know.

--
Craig Ringer


pgsql-sql by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: Update and trigger
Next
From: "Medi Montaseri"
Date:
Subject: Re: Update and trigger