Re: BUG #5894: Rules' behaviour when SERIAL data types are used

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Piergiorgio Buongiovanni" <piergiorgio(dot)buongiovanni(at)netspa(dot)it>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5894: Rules' behaviour when SERIAL data types are used
Date: 2011-02-18 18:21:12
Message-ID: 11536.1298053272@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Piergiorgio Buongiovanni" <piergiorgio(dot)buongiovanni(at)netspa(dot)it> writes:
> We are experiencing a problem on using rules and serial data types with
> PostgreSQL.
> We are trying to align two tables in two different schemas through rules and
> the main table has a column of data type SERIAL.
> ...
> Now we create a rule in order to align l10n.prova when a row is inserted in
> business.prova:

> CREATE OR REPLACE RULE _Prova_Ins AS ON INSERT
> TO business.Prova
> DO ALSO INSERT INTO l10n.Prova VALUES (NEW.iSId, NEW.cName);

By and large, rules don't work very well with commands involving
volatile functions like nextval(). That's because a rule is a macro
and the macro expansion can result in multiple calls of the volatile
function.

Best advice is to use a trigger, not a rule, for propagating changes
from one table to another.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2011-02-18 19:02:31 Re: BUG #5878: BTREE_BUILD_STATS causes 'make check' to fail
Previous Message Tom Lane 2011-02-18 17:35:13 Re: postgresql 9.0.3: parallel restore fails with comments on indices