]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Yet further fixes for multi-row VALUES lists for updatable views.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 11 Oct 2022 22:24:15 +0000 (18:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 11 Oct 2022 22:24:15 +0000 (18:24 -0400)
commitaddde9bc6caf2563f01ecea1ff01e22c328da1ad
treec452e51b729f76e4c92a581d01dbf5208080e2ec
parentdd82638734ed37fc0fa7a56050d636890ed8877c
Yet further fixes for multi-row VALUES lists for updatable views.

DEFAULT markers appearing in an INSERT on an updatable view
could be mis-processed if they were in a multi-row VALUES clause.
This would lead to strange errors such as "cache lookup failed
for type NNNN", or in older branches even to crashes.

The cause is that commit 41531e42d tried to re-use rewriteValuesRTE()
to remove any SetToDefault nodes (that hadn't previously been replaced
by the view's own default values) appearing in "product" queries,
that is DO ALSO queries.  That's fundamentally wrong because the
DO ALSO queries might not even be INSERTs; and even if they are,
their targetlists don't necessarily match the view's column list,
so that almost all the logic in rewriteValuesRTE() is inapplicable.

What we want is a narrow focus on replacing any such nodes with NULL
constants.  (That is, in this context we are interpreting the defaults
as being strictly those of the view itself; and we already replaced
any that aren't NULL.)  We could add still more !force_nulls tests
to further lobotomize rewriteValuesRTE(); but it seems cleaner to
split out this case to a new function, restoring rewriteValuesRTE()
to the charter it had before.

Per bug #17633 from jiye_sw.  Patch by me, but thanks to
Richard Guo and Japin Li for initial investigation.
Back-patch to all supported branches, as the previous fix was.

Discussion: https://postgr.es/m/17633-98cc85e1fa91e905@postgresql.org
src/backend/rewrite/rewriteHandler.c
src/test/regress/expected/updatable_views.out
src/test/regress/sql/updatable_views.sql