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

Commitae7b1dd

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 parent079ac01 commitae7b1dd

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
@@ -2768,11 +2768,14 @@ ExecInitSubscriptingRef(ExprEvalStep *scratch, SubscriptingRef *sbsref,
27682768
* (We could use this in FieldStore too, but in that case passing the old
27692769
* value is so cheap there's no need.)
27702770
*
2771-
* Note: it might seem that this needs to recurse, but it does not; the
2772-
* CaseTestExpr, if any, will be directly the arg or refexpr of the top-level
2773-
* node. Nested-assignment situations give rise to expression trees in which
2774-
* each level of assignment has its own CaseTestExpr, and the recursive
2775-
* structure appears within the newvals or refassgnexpr field.
2771+
* Note: it might seem that this needs to recurse, but in most cases it does
2772+
* not; the CaseTestExpr, if any, will be directly the arg or refexpr of the
2773+
* top-level node. Nested-assignment situations give rise to expression
2774+
* trees in which each level of assignment has its own CaseTestExpr, and the
2775+
* recursive structure appears within the newvals or refassgnexpr field.
2776+
* There is an exception, though: if the array is an array-of-domain, we will
2777+
* have a CoerceToDomain as the refassgnexpr, and we need to be able to look
2778+
* through that.
27762779
*/
27772780
staticbool
27782781
isAssignmentIndirectionExpr(Expr*expr)
@@ -2793,6 +2796,12 @@ isAssignmentIndirectionExpr(Expr *expr)
27932796
if (sbsRef->refexpr&&IsA(sbsRef->refexpr,CaseTestExpr))
27942797
return true;
27952798
}
2799+
elseif (IsA(expr,CoerceToDomain))
2800+
{
2801+
CoerceToDomain*cd= (CoerceToDomain*)expr;
2802+
2803+
returnisAssignmentIndirectionExpr(cd->arg);
2804+
}
27962805
return false;
27972806
}
27982807

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,30 @@ LINE 1: update dposintatable set (f1[2])[1] = array[98];
518518
drop table dposintatable;
519519
drop domain posint cascade;
520520
NOTICE: drop cascades to type dposinta
521+
-- Test arrays over domains of composite
522+
create type comptype as (cf1 int, cf2 int);
523+
create domain dcomptype as comptype check ((value).cf1 > 0);
524+
create table dcomptable (f1 dcomptype[]);
525+
insert into dcomptable values (null);
526+
update dcomptable set f1[1].cf2 = 5;
527+
table dcomptable;
528+
f1
529+
----------
530+
{"(,5)"}
531+
(1 row)
532+
533+
update dcomptable set f1[1].cf1 = -1; -- fail
534+
ERROR: value for domain dcomptype violates check constraint "dcomptype_check"
535+
update dcomptable set f1[1].cf1 = 1;
536+
table dcomptable;
537+
f1
538+
-----------
539+
{"(1,5)"}
540+
(1 row)
541+
542+
drop table dcomptable;
543+
drop type comptype cascade;
544+
NOTICE: drop cascades to type dcomptype
521545
-- Test not-null restrictions
522546
create domain dnotnull varchar(15) NOT NULL;
523547
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
@@ -268,6 +268,23 @@ drop table dposintatable;
268268
dropdomain posint cascade;
269269

270270

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

273290
createdomaindnotnullvarchar(15)NOT NULL;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp