1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-03 15:22:11 +03:00

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 plain
composites.  That's because isAssignmentIndirectionExpr()
failed to cope with the CoerceToDomain node that would appear
in the expression tree in this case.  The result would typically
be a crash, and even if we accidentally didn't crash, we'd not
correctly preserve other fields of the same array element.

Per report from Onder Kalaci.  Back-patch to v11 where arrays of
domains came in.

Discussion: https://postgr.es/m/PH0PR21MB132823A46AA36F0685B7A29AD8BD9@PH0PR21MB1328.namprd21.prod.outlook.com
This commit is contained in:
Tom Lane
2021-10-19 13:54:45 -04:00
parent f627fd547a
commit 04dae19f4d
3 changed files with 55 additions and 5 deletions

View File

@@ -512,6 +512,30 @@ LINE 1: update dposintatable set (f1[2])[1] = array[98];
drop table dposintatable;
drop domain posint cascade;
NOTICE: drop cascades to type dposinta
-- Test arrays over domains of composite
create type comptype as (cf1 int, cf2 int);
create domain dcomptype as comptype check ((value).cf1 > 0);
create table dcomptable (f1 dcomptype[]);
insert into dcomptable values (null);
update dcomptable set f1[1].cf2 = 5;
table dcomptable;
f1
----------
{"(,5)"}
(1 row)
update dcomptable set f1[1].cf1 = -1; -- fail
ERROR: value for domain dcomptype violates check constraint "dcomptype_check"
update dcomptable set f1[1].cf1 = 1;
table dcomptable;
f1
-----------
{"(1,5)"}
(1 row)
drop table dcomptable;
drop type comptype cascade;
NOTICE: drop cascades to type dcomptype
-- Test not-null restrictions
create domain dnotnull varchar(15) NOT NULL;
create domain dnull varchar(15);

View File

@@ -267,6 +267,23 @@ drop table dposintatable;
drop domain posint cascade;
-- Test arrays over domains of composite
create type comptype as (cf1 int, cf2 int);
create domain dcomptype as comptype check ((value).cf1 > 0);
create table dcomptable (f1 dcomptype[]);
insert into dcomptable values (null);
update dcomptable set f1[1].cf2 = 5;
table dcomptable;
update dcomptable set f1[1].cf1 = -1; -- fail
update dcomptable set f1[1].cf1 = 1;
table dcomptable;
drop table dcomptable;
drop type comptype cascade;
-- Test not-null restrictions
create domain dnotnull varchar(15) NOT NULL;