Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hde2e-0007hH-Oh for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Jun 2019 17:06:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hde2d-0001eP-LD for pgsql-bugs@arkaria.postgresql.org; Wed, 19 Jun 2019 17:06:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hde2d-0001eC-AB for pgsql-bugs@lists.postgresql.org; Wed, 19 Jun 2019 17:06:35 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hde2a-0005cE-Cc for pgsql-bugs@lists.postgresql.org; Wed, 19 Jun 2019 17:06:34 +0000 Received: from [192.168.127.1] (port=16238 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1hde2W-000GqW-LY; Wed, 19 Jun 2019 17:06:28 +0000 Received: from [127.0.0.1] (port=32350 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1hde2V-000F2R-VN; Wed, 19 Jun 2019 17:06:28 +0000 From: Andrew Gierth To: pgsql-bugs@lists.postgresql.org, lizardus@ya.ru Subject: Re: BUG #15855: Using 'nextval' inside INSERT RULE in case of bulk data insertion. In-Reply-To: <15855-52f9fbeb62a30b76@postgresql.org> (PG Bug reporting form's message of "Mon, 17 Jun 2019 08:04:06 +0000") Message-ID: <87fto51pm3.fsf@news-spur.riddles.org.uk> References: <15855-52f9fbeb62a30b76@postgresql.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Wed, 19 Jun 2019 18:06:26 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "PG" == PG Bug reporting form writes: PG> I use two SQL commands in RULE INSTEAD INSERT. I expect that in PG> case of bulk data insertion they will be sequentially executed for PG> each record. I expect that during a bulk insert, they will be PG> sequentially executed for each record. However, firstly the first PG> SQL-command is executed all records, then the second for all PG> records. As a result, I get one value for all 'nextval' calls. This isn't a bug, it's just how rules work. Use triggers instead. https://wiki.postgresql.org/wiki/Don't_Do_This#Don.27t_use_rules -- Andrew (irc:RhodiumToad)