]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Make rewriter prevent auto-updates on views with conditional INSTEAD rules.
authorDean Rasheed <dean.a.rasheed@gmail.com>
Tue, 14 Jan 2020 09:50:13 +0000 (09:50 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Tue, 14 Jan 2020 09:50:13 +0000 (09:50 +0000)
commit353cd826f44537871063c6525dc0e108c974a68c
tree652965d7e09f3f4267035d0399a1dc2293c57da4
parentf9e95252a311b65e3e5aa9cb56cec2736e2b1cfa
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
src/backend/executor/execMain.c
src/backend/rewrite/rewriteHandler.c
src/test/regress/expected/updatable_views.out
src/test/regress/sql/updatable_views.sql