pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: lizardus@ya.ru
Subject: BUG #15855: Using 'nextval' inside INSERT RULE in case of bulk data insertion.
Date: Mon, 17 Jun 2019 08:04:06 +0000
Message-ID: <15855-52f9fbeb62a30b76@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      15855
Logged by:          Ivan
Email address:      lizardus@ya.ru
PostgreSQL version: 10.8
Operating system:   not matter
Description:        

I use two SQL commands in RULE INSTEAD INSERT. I expect that in case of bulk
data insertion they will be sequentially executed for each record. I expect
that during a bulk insert, they will be sequentially executed for each
record. However, firstly the first SQL-command is executed all records, then
the second for all records. As a result, I get one value for all 'nextval'
calls.
Script for reproduce:
----------------------------------------
CREATE SEQUENCE s;
CREATE TABLE t1
(
  id integer default nextval('s') primary key,
  col1 integer
);
create table t2 (
  id integer references t1(id),
  col2 integer
);
create view v1 as (
  select * from t1
  left join t2 using(id)
);
CREATE OR REPLACE RULE "_INSERT" AS
    ON INSERT TO v1 DO INSTEAD (
    INSERT INTO t1 VALUES (nextval('s'::regclass),NEW.col1);
    INSERT INTO t2 VALUES (currval('s'::regclass),NEW.col2);
);
insert into v1 (col1,col2) select a, b from
(values(10,11),(12,13),(14,15),(16,17),(18,19),(20,21)) t(a,b);
select * from v1 order by id;
-------------------------------------------
RESULT:
1;10;NULL
2;12;NULL
3;14;NULL
4;16;NULL
5;18;NULL
6;20;11
6;20;21
6;20;13
6;20;15
6;20;17
6;20;19

EXPECTED RESULT:
1;10;11
2;12;13
3;14;15
4;16;17
5;18;19
6;20;21



view thread (2+ messages)  latest in thread

Message-ID: <15855-52f9fbeb62a30b76@postgresql.org>
Permalink:  ../15855-52f9fbeb62a30b76@postgresql.org/
Also on:    postgresql.org/message-id/15855-52f9fbeb62a30b76@postgresql.org

 · 

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: noreply@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>
  References: <15855-52f9fbeb62a30b76@postgresql.org>

* 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