Skip to content

Commit 048caf8

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 e76fbcf commit 048caf8

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
@@ -2839,8 +2839,8 @@ ExecInitSubscriptingRef(ExprEvalStep *scratch, SubscriptingRef *sbsref,
28392839
* trees in which each level of assignment has its own CaseTestExpr, and the
28402840
* recursive structure appears within the newvals or refassgnexpr field.
28412841
* There is an exception, though: if the array is an array-of-domain, we will
2842-
* have a CoerceToDomain as the refassgnexpr, and we need to be able to look
2843-
* through that.
2842+
* have a CoerceToDomain or RelabelType as the refassgnexpr, and we need to
2843+
* be able to look through that.
28442844
*/
28452845
static bool
28462846
isAssignmentIndirectionExpr(Expr *expr)
@@ -2867,6 +2867,12 @@ isAssignmentIndirectionExpr(Expr *expr)
28672867

28682868
return isAssignmentIndirectionExpr(cd->arg);
28692869
}
2870+
else if (IsA(expr, RelabelType))
2871+
{
2872+
RelabelType *r = (RelabelType *) expr;
2873+
2874+
return isAssignmentIndirectionExpr(r->arg);
2875+
}
28702876
return false;
28712877
}
28722878

src/test/regress/expected/domain.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,15 @@ table dcomptable;
562562
{"(1,5)"}
563563
(1 row)
564564

565+
-- if there's no constraints, a different code path is taken:
566+
alter domain dcomptype drop constraint dcomptype_check;
567+
update dcomptable set f1[1].cf1 = -1; -- now ok
568+
table dcomptable;
569+
f1
570+
------------
571+
{"(-1,5)"}
572+
(1 row)
573+
565574
drop table dcomptable;
566575
drop type comptype cascade;
567576
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
@@ -289,6 +289,10 @@ table dcomptable;
289289
update dcomptable set f1[1].cf1 = -1; -- fail
290290
update dcomptable set f1[1].cf1 = 1;
291291
table dcomptable;
292+
-- if there's no constraints, a different code path is taken:
293+
alter domain dcomptype drop constraint dcomptype_check;
294+
update dcomptable set f1[1].cf1 = -1; -- now ok
295+
table dcomptable;
292296

293297
drop table dcomptable;
294298
drop type comptype cascade;

0 commit comments

Comments
 (0)