diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2024-03-14 14:57:16 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2024-03-14 14:57:16 -0400 |
commit | b4a71cf65d70b98aaf890b13ec600e340ff69e3f (patch) | |
tree | 4ef3a8e2c41649665a80f6c8caa8e517709cfd82 /src/backend/rewrite/rewriteHandler.c | |
parent | d1162cfda885c5a8cb9cebfc8eed9f1d76855e83 (diff) | |
download | postgresql-b4a71cf65d70b98aaf890b13ec600e340ff69e3f.tar.gz postgresql-b4a71cf65d70b98aaf890b13ec600e340ff69e3f.zip |
Make INSERT-from-multiple-VALUES-rows handle domain target columns.
Commit a3c7a993d fixed some cases involving target columns that are
arrays or composites by applying transformAssignedExpr to the VALUES
entries, and then stripping off any assignment ArrayRefs or
FieldStores that the transformation added. But I forgot about domains
over arrays or composites :-(. Such cases would either fail with
surprising complaints about mismatched datatypes, or insert unexpected
coercions that could lead to odd results. To fix, extend the
stripping logic to get rid of CoerceToDomain if it's atop an ArrayRef
or FieldStore.
While poking at this, I realized that there's a poorly documented and
not-at-all-tested behavior nearby: we coerce each VALUES column to
the domain type separately, and rely on the rewriter to merge those
operations so that the domain constraints are checked only once.
If that merging did not happen, it's entirely possible that we'd get
unexpected domain constraint failures due to checking a
partially-updated container value. There's no bug there, but while
we're here let's improve the commentary about it and add some test
cases that explicitly exercise that behavior.
Per bug #18393 from Pablo Kharo. Back-patch to all supported
branches.
Discussion: https://postgr.es/m/18393-65fedb1a0de9260d@postgresql.org
Diffstat (limited to 'src/backend/rewrite/rewriteHandler.c')
-rw-r--r-- | src/backend/rewrite/rewriteHandler.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c index 89187d9af2e..7a46e8b3541 100644 --- a/src/backend/rewrite/rewriteHandler.c +++ b/src/backend/rewrite/rewriteHandler.c @@ -1086,9 +1086,9 @@ process_matched_tle(TargetEntry *src_tle, * resulting in each assignment containing a CoerceToDomain node over a * FieldStore or SubscriptingRef. These should have matching target * domains, so we strip them and reconstitute a single CoerceToDomain over - * the combined FieldStore/SubscriptingRef nodes. (Notice that this has the - * result that the domain's checks are applied only after we do all the - * field or element updates, not after each one. This is arguably desirable.) + * the combined FieldStore/SubscriptingRef nodes. (Notice that this has + * the result that the domain's checks are applied only after we do all + * the field or element updates, not after each one. This is desirable.) *---------- */ src_expr = (Node *) src_tle->expr; |