pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix DEFAULT-handling in multi-row VALUES lists for updatable vie
Date: Wed, 20 Feb 2019 08:37:47 +0000
Message-ID: <E1gwNNz-0002FR-Tp@gemulon.postgresql.org> (raw)

Fix DEFAULT-handling in multi-row VALUES lists for updatable views.

INSERT ... VALUES for a single VALUES row is implemented differently
from a multi-row VALUES list, which causes inconsistent behaviour in
the way that DEFAULT items are handled. In particular, when inserting
into an auto-updatable view on top of a table with a column default, a
DEFAULT item in a single VALUES row gets correctly replaced with the
table column's default, but for a multi-row VALUES list it is replaced
with NULL.

Fix this by allowing rewriteValuesRTE() to leave DEFAULT items in the
VALUES list untouched if the target relation is an auto-updatable view
and has no column default, deferring DEFAULT-expansion until the query
against the base relation is rewritten. For all other types of target
relation, including tables and trigger- and rule-updatable views, we
must continue to replace DEFAULT items with NULL in the absence of a
column default.

This is somewhat complicated by the fact that if an auto-updatable
view has DO ALSO rules attached, the VALUES lists for the product
queries need to be handled differently from the original query, since
the product queries need to act like rule-updatable views whereas the
original query has auto-updatable view semantics.

Back-patch to all supported versions.

Reported by Roger Curley (bug #15623). Patch by Amit Langote and me.

Discussion: https://postgr.es/m/15623-5d67a46788ec8b7f@postgresql.org

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2b1971c0318bae45317386877621642cd5ce7849

Modified Files
--------------
src/backend/rewrite/rewriteHandler.c          | 139 +++++++++++++++++++++--
src/test/regress/expected/updatable_views.out | 153 ++++++++++++++++++++++++++
src/test/regress/sql/updatable_views.sql      |  88 +++++++++++++++
3 files changed, 369 insertions(+), 11 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1gwNNz-0002FR-Tp@gemulon.postgresql.org>
Permalink:  ../E1gwNNz-0002FR-Tp@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1gwNNz-0002FR-Tp@gemulon.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-committers@postgresql.org
  Cc: dean.a.rasheed@gmail.com
  Subject: Re: pgsql: Fix DEFAULT-handling in multi-row VALUES lists for updatable vie
  In-Reply-To: <E1gwNNz-0002FR-Tp@gemulon.postgresql.org>
  References: <E1gwNNz-0002FR-Tp@gemulon.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