Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V264d-0002jt-MU for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jul 2013 20:54:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1V264d-0002v9-5f for pgsql-bugs@arkaria.postgresql.org; Wed, 24 Jul 2013 20:54:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V1y2A-0008DR-Ax for pgsql-bugs@postgresql.org; Wed, 24 Jul 2013 12:19:10 +0000 Received: from mail-lb0-f181.google.com ([209.85.217.181]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1V1y26-0001c6-3N for pgsql-bugs@postgresql.org; Wed, 24 Jul 2013 12:19:09 +0000 Received: by mail-lb0-f181.google.com with SMTP id w10so421505lbi.12 for ; Wed, 24 Jul 2013 05:19:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version:x-mailer :x-gm-message-state; bh=S8ZZL4zWRUvQjoPowVVsy/JgM4BTmva8WarW9xOcz2Y=; b=ch+xM+Rllw1Anb+bB+y/2hEtxVKVFSy2NuWjogdCShAiqTbubVzdHWM+Q+2myEaoNP 6fW75whJ0KXK4Fu1+oyGYAOPBNVQWCkmq1sCPOQRj+QqU6wXEYG+w4WT0O88194+O7Di YRqMRuZ89RseKs4xRSS/w6XxY1Dy65Qta0Tn8aN9V81nQYJEqFFd/4N3ePODa/Uq7AlF c1iuv7ciJfN5DbvBziHYwV1pDPHjJZ1hH2fkXTfLmKMIKAf0XlevOGeajYUns00IRozs kF0o2MSh0hPVeynUGNh4UI1qNu6wrdTDH9i0nrqNzFStxNw9V0dUK1Ay7G9Az0HKecul Q5HQ== X-Received: by 10.152.18.202 with SMTP id y10mr16432027lad.80.1374668345543; Wed, 24 Jul 2013 05:19:05 -0700 (PDT) Received: from [10.130.11.119] (cm-84.210.76.250.getinternet.no. [84.210.76.250]) by mx.google.com with ESMTPSA id 8sm14508988lbq.4.2013.07.24.05.19.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 24 Jul 2013 05:19:04 -0700 (PDT) From: Terje Elde Content-Type: multipart/alternative; boundary="Apple-Mail=_C0F04350-8C07-4239-9653-78C6C5BE9BC3" Subject: Single row INSERT on updatable VIEW on top of partitioned table is run against each inheriting table, giving multiple rows from single insert. Message-Id: <3BF82E03-C10D-4238-9EC2-46CFF9983D8F@pam.as> Date: Wed, 24 Jul 2013 14:19:05 +0200 To: pgsql-bugs@postgresql.org Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) X-Mailer: Apple Mail (2.1508) X-Gm-Message-State: ALoCoQlotVl5hV9CGiZaeJbGd+nhtoa9uLAcUcUg/tL7GXFYV85FHauK4kQCA+dDU6J/YOr9Lxt+ X-Pg-Spam-Score: -2.6 (--) 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 --Apple-Mail=_C0F04350-8C07-4239-9653-78C6C5BE9BC3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 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=85=20 bughunt=3D# INSERT INTO cars_view ( runs ) VALUES ( True ); INSERT 0 2 -- =85 one in cars=85=20 bughunt=3D# SELECT count(*) FROM ONLY cars; count=20 ------- 1 (1 row) -- .. and the other in wrecks. bughunt=3D# SELECT count(*) FROM wrecks; count=20 ------- 1 (1 row) bughunt=3D#=20 -- Insert into cars though, leads to single INSERT: bughunt=3D# INSERT INTO cars ( runs ) VALUES ( True ); INSERT 0 1 ---------- end ACTION!=20 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 --Apple-Mail=_C0F04350-8C07-4239-9653-78C6C5BE9BC3 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=windows-1252
<= br>
Right now, that says:
"If the view is = automatically updatable the system will convert any , UPDATEDELETE 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


= --Apple-Mail=_C0F04350-8C07-4239-9653-78C6C5BE9BC3--