pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedSingle row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert.
3+ messages / 2 participants
[nested] [flat]
* Single row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert.
@ 2013-07-24 12:19 Terje Elde <terje@pam.as>
0 siblings, 0 replies; 3+ messages in thread
From: Terje Elde @ 2013-07-24 12:19 UTC (permalink / raw)
To: pgsql-bugs
Hi,
Short summary:
If I run a single INSERT against an updateable VIEW on top of a partitioned table, it's run against all the tables/partitions. I'd expect that with UPDATE and DELETE, but not with INSERT. Result is multiple rows for a single INSERT, one for each table.
I ran into this on 9.3beta1, confirmed on 9.3beta2. Example is run against the latter.
---------- SCHEMA
-- Main table
CREATE TABLE cars (
id serial primary key,
runs boolean not null
);
-- And a table that INHERITS it.
CREATE TABLE wrecks ( ) INHERITS ( cars );
---------- VIEW
-- Simple view
CREATE VIEW cars_view AS
SELECT * FROM cars;
---------- ACTION!
-- INSERTing into the view actually inserts two rows…
bughunt=# INSERT INTO cars_view ( runs ) VALUES ( True );
INSERT 0 2
-- … one in cars…
bughunt=# SELECT count(*) FROM ONLY cars;
count
-------
1
(1 row)
-- .. and the other in wrecks.
bughunt=# SELECT count(*) FROM wrecks;
count
-------
1
(1 row)
bughunt=#
-- Insert into cars though, leads to single INSERT:
bughunt=# INSERT INTO cars ( runs ) VALUES ( True );
INSERT 0 1
---------- end ACTION!
What I'd expect to happen would be for the INSERT to only run against the parimary cars table.
To me, this looks like a bug, but opinions might differ. If this is intended and desirable behaviour, I'd say it at least warrants a mention in the docs, such as under "Updatable views" here:
http://www.postgresql.org/docs/9.3/static/sql-createview.html
Right now, that says:
"If the view is automatically updatable the system will convert any INSERT, UPDATE or DELETE statement on the view into the corresponding statement on the underlying base relation."
If the underlaying relation is cars, I'd expect it to behave more as an insert on cars.
Terje
^ permalink raw reply [nested|flat] 3+ messages in thread
* Single row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert.
@ 2013-07-24 12:37 Terje Elde <terje@elde.net>
2013-07-24 13:11 ` Re: Single row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert. Terje Elde <terje@elde.net>
0 siblings, 1 reply; 3+ messages in thread
From: Terje Elde @ 2013-07-24 12:37 UTC (permalink / raw)
To: pgsql-bugs
Hi,
Short summary:
If I run a single INSERT against an updateable VIEW on top of a partitioned table, it's run against all the tables/partitions. I'd expect that with UPDATE and DELETE, but not with INSERT. Result is multiple rows for a single INSERT, one for each table.
I ran into this on 9.3beta1, confirmed on 9.3beta2. Example is run against the latter.
---------- SCHEMA
-- Main table
CREATE TABLE cars (
id serial primary key,
runs boolean not null
);
-- And a table that INHERITS it.
CREATE TABLE wrecks ( ) INHERITS ( cars );
---------- VIEW
-- Simple view
CREATE VIEW cars_view AS
SELECT * FROM cars;
---------- ACTION!
-- INSERTing into the view actually inserts two rows…
bughunt=# INSERT INTO cars_view ( runs ) VALUES ( True );
INSERT 0 2
-- … one in cars…
bughunt=# SELECT count(*) FROM ONLY cars;
count
-------
1
(1 row)
-- .. and the other in wrecks.
bughunt=# SELECT count(*) FROM wrecks;
count
-------
1
(1 row)
bughunt=#
-- Insert into cars though, leads to single INSERT:
bughunt=# INSERT INTO cars ( runs ) VALUES ( True );
INSERT 0 1
---------- end ACTION!
What I'd expect to happen would be for the INSERT to only run against the parimary cars table.
To me, this looks like a bug, but opinions might differ. If this is intended and desirable behaviour, I'd say it at least warrants a mention in the docs, such as under "Updatable views" here:
http://www.postgresql.org/docs/9.3/static/sql-createview.html
Right now, that says:
"If the view is automatically updatable the system will convert any INSERT, UPDATE or DELETE statement on the view into the corresponding statement on the underlying base relation."
If the underlaying relation is cars, I'd expect it to behave more as an insert on cars.
Terje
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Single row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert.
2013-07-24 12:37 Single row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert. Terje Elde <terje@elde.net>
@ 2013-07-24 13:11 ` Terje Elde <terje@elde.net>
0 siblings, 0 replies; 3+ messages in thread
From: Terje Elde @ 2013-07-24 13:11 UTC (permalink / raw)
To: pgsql-bugs
On Jul 24, 2013, at 2:37 PM, Terje Elde <terje@elde.net> wrote:
> Short summary:
> If I run a single INSERT against an updateable VIEW on top of a partitioned table, it's run against all the tables/partitions. I'd expect that with UPDATE and DELETE, but not with INSERT. Result is multiple rows for a single INSERT, one for each table.
Sorry, while I did scan the last month and the open issues-list before sending, I missed that this had already been identified, patch submitted, and applied:
http://www.postgresql.org/message-id/CAEZATCW4EUi-BqjzYyow0nt84jhOwSDxzbhtbFoRrvUi59NCnQ@mail.gmail....
http://www.postgresql.org/message-id/11683.1372868994@sss.pgh.pa.us
Everything behaves as expected with the patch.
Terje
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2013-07-24 13:11 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-07-24 12:19 Single row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert. Terje Elde <terje@pam.as>
2013-07-24 12:37 Single row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert. Terje Elde <terje@elde.net>
2013-07-24 13:11 ` Terje Elde <terje@elde.net>
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