Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 064eb89

Browse files
committed
Fix assignment to array of domain over composite, redux.
Commit 3e310d8 taught isAssignmentIndirectionExpr() to look through CoerceToDomain nodes. That's not sufficient, because since commit 04fe805 it's been possible for the planner to simplify CoerceToDomain to RelabelType when the domain has no constraints to enforce. So we need to look through RelabelType too. Per bug #17897 from Alexander Lakhin. Although 3e310d8 was back-patched to v11, it seems sufficient to apply this change to v12 and later, since 04fe805 came in in v12. Dmitry Dolgov Discussion: https://postgr.es/m/17897-4216c546c3874044@postgresql.org
1 parent d6b5dee commit 064eb89

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/backend/executor/execExpr.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3225,8 +3225,8 @@ ExecInitSubscriptingRef(ExprEvalStep *scratch, SubscriptingRef *sbsref,
32253225
* trees in which each level of assignment has its own CaseTestExpr, and the
32263226
* recursive structure appears within the newvals or refassgnexpr field.
32273227
* There is an exception, though: if the array is an array-of-domain, we will
3228-
* have a CoerceToDomain as the refassgnexpr, and we need to be able to look
3229-
* through that.
3228+
* have a CoerceToDomain or RelabelType as the refassgnexpr, and we need to
3229+
* be able to look through that.
32303230
*/
32313231
static bool
32323232
isAssignmentIndirectionExpr(Expr *expr)
@@ -3253,6 +3253,12 @@ isAssignmentIndirectionExpr(Expr *expr)
32533253

32543254
return isAssignmentIndirectionExpr(cd->arg);
32553255
}
3256+
else if (IsA(expr, RelabelType))
3257+
{
3258+
RelabelType *r = (RelabelType *) expr;
3259+
3260+
return isAssignmentIndirectionExpr(r->arg);
3261+
}
32563262
return false;
32573263
}
32583264

src/test/regress/expected/domain.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,15 @@ table dcomptable;
606606
{"(1,5)"}
607607
(1 row)
608608

609+
-- if there's no constraints, a different code path is taken:
610+
alter domain dcomptype drop constraint dcomptype_check;
611+
update dcomptable set f1[1].cf1 = -1; -- now ok
612+
table dcomptable;
613+
f1
614+
------------
615+
{"(-1,5)"}
616+
(1 row)
617+
609618
drop table dcomptable;
610619
drop type comptype cascade;
611620
NOTICE: drop cascades to type dcomptype

src/test/regress/sql/domain.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ table dcomptable;
307307
update dcomptable set f1[1].cf1 = -1; -- fail
308308
update dcomptable set f1[1].cf1 = 1;
309309
table dcomptable;
310+
-- if there's no constraints, a different code path is taken:
311+
alter domain dcomptype drop constraint dcomptype_check;
312+
update dcomptable set f1[1].cf1 = -1; -- now ok
313+
table dcomptable;
310314

311315
drop table dcomptable;
312316
drop type comptype cascade;

0 commit comments

Comments
 (0)