pgsql: Make rewriter prevent auto-updates on views with conditional INS

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Make rewriter prevent auto-updates on views with conditional INS
Date: 2020-01-14 09:58:06
Message-ID: E1irIxa-00072X-Fq@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make rewriter prevent auto-updates on views with conditional INSTEAD rules.

A view with conditional INSTEAD rules and no unconditional INSTEAD
rules or INSTEAD OF triggers is not auto-updatable. Previously we
relied on a check in the executor to catch this, but that's
problematic since the planner may fail to properly handle such a query
and thus return a particularly unhelpful error to the user, before
reaching the executor check.

Instead, trap this in the rewriter and report the correct error there.
Doing so also allows us to include more useful error detail than the
executor check can provide. This doesn't change the existing behaviour
of updatable views; it merely ensures that useful error messages are
reported when a view isn't updatable.

Per report from Pengzhou Tang, though not adopting that suggested fix.
Back-patch to all supported branches.

Discussion: https://postgr.es/m/CAG4reAQn+4xB6xHJqWdtE0ve_WqJkdyCV4P=trYr4Kn8_3_PEA@mail.gmail.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9bdb1f0e37d4f65cdc32cec1563744dc92213d71

Modified Files
--------------
src/backend/executor/execMain.c | 8 ++--
src/backend/rewrite/rewriteHandler.c | 60 ++++++++++++++++++++++++---
src/test/regress/expected/updatable_views.out | 21 ++++++++++
src/test/regress/sql/updatable_views.sql | 14 +++++++
4 files changed, 94 insertions(+), 9 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2020-01-14 12:45:23 pgsql: ALTER TABLE ... ALTER COLUMN ... DROP EXPRESSION
Previous Message Amit Kapila 2020-01-14 02:58:09 pgsql: Revert test added by commit d207038053.