Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cFN4A-0007dO-IG for pgsql-bugs@arkaria.postgresql.org; Fri, 09 Dec 2016 15:26:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cFN4A-0001EE-57 for pgsql-bugs@arkaria.postgresql.org; Fri, 09 Dec 2016 15:26:30 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cFN3V-0000UQ-J1 for pgsql-bugs@postgresql.org; Fri, 09 Dec 2016 15:25:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cFN3T-0001lB-33 for pgsql-bugs@postgresql.org; Fri, 09 Dec 2016 15:25:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id uB9FPbPJ016623; Fri, 9 Dec 2016 10:25:38 -0500 From: Tom Lane To: =?UTF-8?B?0JDQu9C10LrRgdCw0L3QtNGA?= cc: pgsql-bugs@postgresql.org Subject: Re: =?UTF-8?B?YnVnIGluIFJVTEUgaW5zZXJ0?= In-reply-to: <1481285920.491235434@f66.i.mail.ru> References: <1481285920.491235434@f66.i.mail.ru> Comments: In-reply-to =?UTF-8?B?0JDQu9C10LrRgdCw0L3QtNGA?= message dated "Fri, 09 Dec 2016 15:18:40 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16621.1481297137.1@sss.pgh.pa.us> Date: Fri, 09 Dec 2016 10:25:37 -0500 Message-ID: <16622.1481297137@sss.pgh.pa.us> X-Pg-Spam-Score: -4.9 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org =?UTF-8?B?0JDQu9C10LrRgdCw0L3QtNGA?= writes: > Strange the rule works for an insertion This is expected behavior, because the rule works like a macro, and you have a volatile argument (that is, the nextval() call for the serial column's default) being passed to it and thereby being executed twice. IOW, what you wrote is equivalent to insert into test(id, name) values (nextval('test_id_seq'), '1'), (nextval('test_id_seq'), '2'), (nextval('test_id_seq'), '3'); and that executes, then the rule causes this to also be executed: insert into v_test (v_id, v_name) values (nextval('test_id_seq'), '1'), (nextval('test_id_seq'), '2'), (nextval('test_id_seq'), '3'); What you seem to want would be much more reliably done with a trigger. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs