Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04dae19

Browse files
committed
Fix assignment to array of domain over composite.
An update such as "UPDATE ... SET fld[n].subfld = whatever"failed if the array elements were domains rather than plaincomposites. That's because isAssignmentIndirectionExpr()failed to cope with the CoerceToDomain node that would appearin the expression tree in this case. The result would typicallybe a crash, and even if we accidentally didn't crash, we'd notcorrectly preserve other fields of the same array element.Per report from Onder Kalaci. Back-patch to v11 where arrays ofdomains came in.Discussion:https://postgr.es/m/PH0PR21MB132823A46AA36F0685B7A29AD8BD9@PH0PR21MB1328.namprd21.prod.outlook.com
1 parentf627fd5 commit04dae19

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

‎src/backend/executor/execExpr.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,11 +3076,14 @@ ExecInitSubscriptingRef(ExprEvalStep *scratch, SubscriptingRef *sbsref,
30763076
* (We could use this in FieldStore too, but in that case passing the old
30773077
* value is so cheap there's no need.)
30783078
*
3079-
* Note: it might seem that this needs to recurse, but it does not; the
3080-
* CaseTestExpr, if any, will be directly the arg or refexpr of the top-level
3081-
* node. Nested-assignment situations give rise to expression trees in which
3082-
* each level of assignment has its own CaseTestExpr, and the recursive
3083-
* structure appears within the newvals or refassgnexpr field.
3079+
* Note: it might seem that this needs to recurse, but in most cases it does
3080+
* not; the CaseTestExpr, if any, will be directly the arg or refexpr of the
3081+
* top-level node. Nested-assignment situations give rise to expression
3082+
* trees in which each level of assignment has its own CaseTestExpr, and the
3083+
* recursive structure appears within the newvals or refassgnexpr field.
3084+
* There is an exception, though: if the array is an array-of-domain, we will
3085+
* have a CoerceToDomain as the refassgnexpr, and we need to be able to look
3086+
* through that.
30843087
*/
30853088
staticbool
30863089
isAssignmentIndirectionExpr(Expr*expr)
@@ -3101,6 +3104,12 @@ isAssignmentIndirectionExpr(Expr *expr)
31013104
if (sbsRef->refexpr&&IsA(sbsRef->refexpr,CaseTestExpr))
31023105
return true;
31033106
}
3107+
elseif (IsA(expr,CoerceToDomain))
3108+
{
3109+
CoerceToDomain*cd= (CoerceToDomain*)expr;
3110+
3111+
returnisAssignmentIndirectionExpr(cd->arg);
3112+
}
31043113
return false;
31053114
}
31063115

‎src/test/regress/expected/domain.out

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,30 @@ LINE 1: update dposintatable set (f1[2])[1] = array[98];
512512
drop table dposintatable;
513513
drop domain posint cascade;
514514
NOTICE: drop cascades to type dposinta
515+
-- Test arrays over domains of composite
516+
create type comptype as (cf1 int, cf2 int);
517+
create domain dcomptype as comptype check ((value).cf1 > 0);
518+
create table dcomptable (f1 dcomptype[]);
519+
insert into dcomptable values (null);
520+
update dcomptable set f1[1].cf2 = 5;
521+
table dcomptable;
522+
f1
523+
----------
524+
{"(,5)"}
525+
(1 row)
526+
527+
update dcomptable set f1[1].cf1 = -1; -- fail
528+
ERROR: value for domain dcomptype violates check constraint "dcomptype_check"
529+
update dcomptable set f1[1].cf1 = 1;
530+
table dcomptable;
531+
f1
532+
-----------
533+
{"(1,5)"}
534+
(1 row)
535+
536+
drop table dcomptable;
537+
drop type comptype cascade;
538+
NOTICE: drop cascades to type dcomptype
515539
-- Test not-null restrictions
516540
create domain dnotnull varchar(15) NOT NULL;
517541
create domain dnull varchar(15);

‎src/test/regress/sql/domain.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,23 @@ drop table dposintatable;
267267
dropdomain posint cascade;
268268

269269

270+
-- Test arrays over domains of composite
271+
272+
createtypecomptypeas (cf1int, cf2int);
273+
createdomaindcomptypeas comptypecheck ((value).cf1>0);
274+
275+
createtabledcomptable (f1 dcomptype[]);
276+
insert into dcomptablevalues (null);
277+
update dcomptableset f1[1].cf2=5;
278+
table dcomptable;
279+
update dcomptableset f1[1].cf1=-1;-- fail
280+
update dcomptableset f1[1].cf1=1;
281+
table dcomptable;
282+
283+
droptable dcomptable;
284+
droptype comptype cascade;
285+
286+
270287
-- Test not-null restrictions
271288

272289
createdomaindnotnullvarchar(15)NOT NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp