Re: BEFORE UPDATE trigger also fires at insert?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Clemens Eisserer <linuxhippy(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: BEFORE UPDATE trigger also fires at insert?
Date: 2011-05-08 16:47:17
Message-ID: 21233.1304873237@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Clemens Eisserer <linuxhippy(at)gmail(dot)com> writes:
> I've defined a small trigger to increment a field each time the row is updated:

>> CREATE TRIGGER inc_trigger BEFORE UPDATE ON Table FOR EACH ROW EXECUTE PROCEDURE inc_function();

> Works quite well, however the trigger is also fired if the table
> itself is modified.
> When deleting or inserting a single row, the trigger is executed for
> all rows contained in the table.

> Is this intetional, and if so, how can I get the behaviour to only
> execute the trigger when an update on the relation is performed?

That trigger definition will most certainly only fire on updates.

Are you sure you don't have additional trigger definitions calling the
same function? Or maybe there are some rules on the table that result
in update actions?

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christophe Pettus 2011-05-08 17:23:44 Time zone specifications, abbreviations vs full names
Previous Message Clemens Eisserer 2011-05-08 13:26:22 BEFORE UPDATE trigger also fires at insert?