Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 43A391337BD8 for ; Fri, 18 Feb 2011 14:21:28 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 70313-03 for ; Fri, 18 Feb 2011 18:21:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 52F1E1337BCF for ; Fri, 18 Feb 2011 14:21:16 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p1IILC17011537; Fri, 18 Feb 2011 13:21:12 -0500 (EST) To: "Piergiorgio Buongiovanni" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #5894: Rules' behaviour when SERIAL data types are used In-reply-to: <201102181547.p1IFlOsE056574@wwwmaster.postgresql.org> References: <201102181547.p1IFlOsE056574@wwwmaster.postgresql.org> Comments: In-reply-to "Piergiorgio Buongiovanni" message dated "Fri, 18 Feb 2011 15:47:24 +0000" Date: Fri, 18 Feb 2011 13:21:12 -0500 Message-ID: <11536.1298053272@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201102/165 X-Sequence-Number: 29437 "Piergiorgio Buongiovanni" 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