pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Piergiorgio Buongiovanni <piergiorgio.buongiovanni@netspa.it>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5894: Rules' behaviour when SERIAL data types are used
Date: Fri, 18 Feb 2011 13:21:12 -0500
Message-ID: <11536.1298053272@sss.pgh.pa.us> (raw)
In-Reply-To: <201102181547.p1IFlOsE056574@wwwmaster.postgresql.org>
References: <201102181547.p1IFlOsE056574@wwwmaster.postgresql.org>

"Piergiorgio Buongiovanni" <piergiorgio.buongiovanni@netspa.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



view thread (2+ messages)

Message-ID: <11536.1298053272@sss.pgh.pa.us>
Permalink:  ../11536.1298053272@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/11536.1298053272@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, piergiorgio.buongiovanni@netspa.it
  Subject: Re: BUG #5894: Rules' behaviour when SERIAL data types are used
  In-Reply-To: <11536.1298053272@sss.pgh.pa.us>
  References: <201102181547.p1IFlOsE056574@wwwmaster.postgresql.org> <11536.1298053272@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox