aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/oracle_compat.c
diff options
context:
space:
mode:
authorDean Rasheed <dean.a.rasheed@gmail.com>2023-02-23 10:56:41 +0000
committerDean Rasheed <dean.a.rasheed@gmail.com>2023-02-23 10:56:41 +0000
commit226da3d4767083b58b9d1acf67b1402865d359bf (patch)
tree6368ae8aa1490725a848e5f76ca5279a89869cbf /src/backend/utils/adt/oracle_compat.c
parent4df581fa0f4b663141901d87817f77ec695c6d22 (diff)
downloadpostgresql-226da3d4767083b58b9d1acf67b1402865d359bf.tar.gz
postgresql-226da3d4767083b58b9d1acf67b1402865d359bf.zip
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
Diffstat (limited to 'src/backend/utils/adt/oracle_compat.c')
0 files changed, 0 insertions, 0 deletions