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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-sql by date

  From Date Subject
Next Message Medi Montaseri 2008-06-11 07:54:55 Re: Update and trigger
Previous Message A. Kretschmer 2008-06-11 05:21:07 Re: Update and trigger