Skip to content

Commit 9b104a2

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 e9884e9 commit 9b104a2

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
@@ -3132,8 +3132,8 @@ ExecInitSubscriptingRef(ExprEvalStep *scratch, SubscriptingRef *sbsref,
31323132
* trees in which each level of assignment has its own CaseTestExpr, and the
31333133
* recursive structure appears within the newvals or refassgnexpr field.
31343134
* There is an exception, though: if the array is an array-of-domain, we will
3135-
* have a CoerceToDomain as the refassgnexpr, and we need to be able to look
3136-
* through that.
3135+
* have a CoerceToDomain or RelabelType as the refassgnexpr, and we need to
3136+
* be able to look through that.
31373137
*/
31383138
static bool
31393139
isAssignmentIndirectionExpr(Expr *expr)
@@ -3160,6 +3160,12 @@ isAssignmentIndirectionExpr(Expr *expr)
31603160

31613161
return isAssignmentIndirectionExpr(cd->arg);
31623162
}
3163+
else if (IsA(expr, RelabelType))
3164+
{
3165+
RelabelType *r = (RelabelType *) expr;
3166+
3167+
return isAssignmentIndirectionExpr(r->arg);
3168+
}
31633169
return false;
31643170
}
31653171

src/test/regress/expected/domain.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,15 @@ table dcomptable;
556556
{"(1,5)"}
557557
(1 row)
558558

559+
-- if there's no constraints, a different code path is taken:
560+
alter domain dcomptype drop constraint dcomptype_check;
561+
update dcomptable set f1[1].cf1 = -1; -- now ok
562+
table dcomptable;
563+
f1
564+
------------
565+
{"(-1,5)"}
566+
(1 row)
567+
559568
drop table dcomptable;
560569
drop type comptype cascade;
561570
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
@@ -288,6 +288,10 @@ table dcomptable;
288288
update dcomptable set f1[1].cf1 = -1; -- fail
289289
update dcomptable set f1[1].cf1 = 1;
290290
table dcomptable;
291+
-- if there's no constraints, a different code path is taken:
292+
alter domain dcomptype drop constraint dcomptype_check;
293+
update dcomptable set f1[1].cf1 = -1; -- now ok
294+
table dcomptable;
291295

292296
drop table dcomptable;
293297
drop type comptype cascade;

0 commit comments

Comments
 (0)