postgresql/src/backend
Dean Rasheed 75c737636b Fix multi-row DEFAULT handling for INSERT ... SELECT rules.
Given an updatable view with a DO ALSO INSERT ... SELECT rule, a
multi-row INSERT ... VALUES query on the view fails if the VALUES list
contains any DEFAULTs that are not replaced by view defaults. This
manifests as an "unrecognized node type" error, or an Assert failure,
in an assert-enabled build.

The reason is that when RewriteQuery() attempts to replace the
remaining DEFAULT items with NULLs in any product queries, using
rewriteValuesRTEToNulls(), it assumes that the VALUES RTE is located
at the same rangetable index in each product query. However, if the
product query is an INSERT ... SELECT, then the VALUES RTE is actually
in the SELECT part of that query (at the same index), rather than the
top-level product query itself.

Fix, by descending to the SELECT in such cases. Note that we can't
simply use getInsertSelectQuery() for this, since that expects to be
given a raw rule action with OLD and NEW placeholder entries, so we
duplicate its logic instead.

While at it, beef up the checks in getInsertSelectQuery() by checking
that the jointree->fromlist node is indeed a RangeTblRef, and that the
RTE it points to has rtekind == RTE_SUBQUERY.

Per bug #17803, from Alexander Lakhin. Back-patch to all supported
branches.

Dean Rasheed, reviewed by Tom Lane.

Discussion: https://postgr.es/m/17803-53c63ed4ecb4eac6%40postgresql.org
2023-02-23 10:53:01 +00:00
..
access Fix handling of multi-column BRIN indexes 2023-02-19 01:46:58 +01:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup Improve TimestampDifferenceMilliseconds to cope with overflow sanely. 2023-01-26 17:09:12 -05:00
bootstrap Update copyright for 2023 2023-01-02 15:00:37 -05:00
catalog Implement ANY_VALUE aggregate 2023-02-22 09:33:07 +01:00
commands Fix corruption of templates after CREATE DATABASE .. STRATEGY WAL_LOG 2023-02-22 10:14:52 +09:00
executor Add missing support for the latest SPI status codes. 2023-02-22 13:23:09 +00:00
foreign Update copyright for 2023 2023-01-02 15:00:37 -05:00
jit Fix various typos in code and tests 2023-02-09 14:43:53 +09:00
lib Fix ILIST_DEBUG build 2023-01-18 10:26:15 -08:00
libpq Add description for new patterns supported in HBA and ident sample files 2023-02-16 07:38:52 +09:00
main Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodes Mark more nodes with attribute no_query_jumble 2023-02-13 09:07:33 +09:00
optimizer Fix some issues with wrong placement of pseudo-constant quals. 2023-02-22 12:39:11 -05:00
parser Fix incorrect format placeholder 2023-02-10 12:00:51 +01:00
partitioning Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
po Update copyright for 2023 2023-01-02 15:00:37 -05:00
port Update copyright for 2023 2023-01-02 15:00:37 -05:00
postmaster Redesign archive modules 2023-02-17 14:26:42 +09:00
regex Update copyright for 2023 2023-01-02 15:00:37 -05:00
replication Fix snapshot handling in logicalmsg_decode 2023-02-22 15:24:18 +01:00
rewrite Fix multi-row DEFAULT handling for INSERT ... SELECT rules. 2023-02-23 10:53:01 +00:00
snowball Update copyright for 2023 2023-01-02 15:00:37 -05:00
statistics Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
storage Remove obsolete coding for early macOS. 2023-02-22 09:55:43 +13:00
tcop Speedup and increase usability of set proc title functions 2023-02-20 16:18:27 +13:00
tsearch Remove useless casts to (void *) in arguments of some system functions 2023-02-07 06:57:59 +01:00
utils Implement ANY_VALUE aggregate 2023-02-22 09:33:07 +01:00
.gitignore
Makefile Redesign archive modules 2023-02-17 14:26:42 +09:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build Redesign archive modules 2023-02-17 14:26:42 +09:00
nls.mk NLS: Put list of available languages into LINGUAS files 2022-07-13 08:19:17 +02:00