Skip site navigation (1) Skip section navigation (2)

Re: Update and trigger

From: Craig Ringer <craig(at)postnewspapers(dot)com(dot)au>
To: Medi Montaseri <montaseri(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Update and trigger
Date: 2008-06-11 05:35:32
Message-ID: 484F6424.5040202@postnewspapers.com.au (view raw or flat)
Thread:
Lists: 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

In response to

pgsql-sql by date

Next:From: Medi MontaseriDate: 2008-06-11 07:54:55
Subject: Re: Update and trigger
Previous:From: A. KretschmerDate: 2008-06-11 05:21:07
Subject: Re: Update and trigger

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group