@@ -107,6 +107,7 @@ INSERT INTO domarrtest values ('{2,2}', '{{"a"},{"c"}}');
107
107
INSERT INTO domarrtest values (NULL, '{{"a","b","c"},{"d","e","f"}}');
108
108
INSERT INTO domarrtest values (NULL, '{{"toolong","b","c"},{"d","e","f"}}');
109
109
ERROR: value too long for type character varying(4)
110
+ INSERT INTO domarrtest (testint4arr[1], testint4arr[3]) values (11,22);
110
111
select * from domarrtest;
111
112
testint4arr | testchar4arr
112
113
---------------+---------------------
@@ -115,7 +116,8 @@ select * from domarrtest;
115
116
{2,2} | {{a,b},{c,d},{e,f}}
116
117
{2,2} | {{a},{c}}
117
118
| {{a,b,c},{d,e,f}}
118
- (5 rows)
119
+ {11,NULL,22} |
120
+ (6 rows)
119
121
120
122
select testint4arr[1], testchar4arr[2:2] from domarrtest;
121
123
testint4arr | testchar4arr
@@ -125,7 +127,8 @@ select testint4arr[1], testchar4arr[2:2] from domarrtest;
125
127
2 | {{c,d}}
126
128
2 | {{c}}
127
129
| {{d,e,f}}
128
- (5 rows)
130
+ 11 |
131
+ (6 rows)
129
132
130
133
select array_dims(testint4arr), array_dims(testchar4arr) from domarrtest;
131
134
array_dims | array_dims
@@ -135,7 +138,8 @@ select array_dims(testint4arr), array_dims(testchar4arr) from domarrtest;
135
138
[1:2] | [1:3][1:2]
136
139
[1:2] | [1:2][1:1]
137
140
| [1:2][1:3]
138
- (5 rows)
141
+ [1:3] |
142
+ (6 rows)
139
143
140
144
COPY domarrtest FROM stdin;
141
145
COPY domarrtest FROM stdin; -- fail
@@ -149,9 +153,21 @@ select * from domarrtest;
149
153
{2,2} | {{a,b},{c,d},{e,f}}
150
154
{2,2} | {{a},{c}}
151
155
| {{a,b,c},{d,e,f}}
156
+ {11,NULL,22} |
152
157
{3,4} | {q,w,e}
153
158
|
154
- (7 rows)
159
+ (8 rows)
160
+
161
+ update domarrtest set
162
+ testint4arr[1] = testint4arr[1] + 1,
163
+ testint4arr[3] = testint4arr[3] - 1
164
+ where testchar4arr is null;
165
+ select * from domarrtest where testchar4arr is null;
166
+ testint4arr | testchar4arr
167
+ ------------------+--------------
168
+ {12,NULL,21} |
169
+ {NULL,NULL,NULL} |
170
+ (2 rows)
155
171
156
172
drop table domarrtest;
157
173
drop domain domainint4arr restrict;
@@ -182,6 +198,92 @@ select pg_typeof('{1,2,3}'::dia || 42); -- should be int[] not dia
182
198
(1 row)
183
199
184
200
drop domain dia;
201
+ -- Test domains over arrays of composite
202
+ create type comptype as (r float8, i float8);
203
+ create domain dcomptypea as comptype[];
204
+ create table dcomptable (d1 dcomptypea unique);
205
+ insert into dcomptable values (array[row(1,2)]::dcomptypea);
206
+ insert into dcomptable values (array[row(3,4), row(5,6)]::comptype[]);
207
+ insert into dcomptable values (array[row(7,8)::comptype, row(9,10)::comptype]);
208
+ insert into dcomptable values (array[row(1,2)]::dcomptypea); -- fail on uniqueness
209
+ ERROR: duplicate key value violates unique constraint "dcomptable_d1_key"
210
+ DETAIL: Key (d1)=({"(1,2)"}) already exists.
211
+ insert into dcomptable (d1[1]) values(row(9,10));
212
+ insert into dcomptable (d1[1].r) values(11);
213
+ select * from dcomptable;
214
+ d1
215
+ --------------------
216
+ {"(1,2)"}
217
+ {"(3,4)","(5,6)"}
218
+ {"(7,8)","(9,10)"}
219
+ {"(9,10)"}
220
+ {"(11,)"}
221
+ (5 rows)
222
+
223
+ select d1[2], d1[1].r, d1[1].i from dcomptable;
224
+ d1 | r | i
225
+ --------+----+----
226
+ | 1 | 2
227
+ (5,6) | 3 | 4
228
+ (9,10) | 7 | 8
229
+ | 9 | 10
230
+ | 11 |
231
+ (5 rows)
232
+
233
+ update dcomptable set d1[2] = row(d1[2].i, d1[2].r);
234
+ select * from dcomptable;
235
+ d1
236
+ --------------------
237
+ {"(1,2)","(,)"}
238
+ {"(3,4)","(6,5)"}
239
+ {"(7,8)","(10,9)"}
240
+ {"(9,10)","(,)"}
241
+ {"(11,)","(,)"}
242
+ (5 rows)
243
+
244
+ update dcomptable set d1[1].r = d1[1].r + 1 where d1[1].i > 0;
245
+ select * from dcomptable;
246
+ d1
247
+ --------------------
248
+ {"(11,)","(,)"}
249
+ {"(2,2)","(,)"}
250
+ {"(4,4)","(6,5)"}
251
+ {"(8,8)","(10,9)"}
252
+ {"(10,10)","(,)"}
253
+ (5 rows)
254
+
255
+ alter domain dcomptypea add constraint c1 check (value[1].r <= value[1].i);
256
+ alter domain dcomptypea add constraint c2 check (value[1].r > value[1].i); -- fail
257
+ ERROR: column "d1" of table "dcomptable" contains values that violate the new constraint
258
+ select array[row(2,1)]::dcomptypea; -- fail
259
+ ERROR: value for domain dcomptypea violates check constraint "c1"
260
+ insert into dcomptable values (array[row(1,2)]::comptype[]);
261
+ insert into dcomptable values (array[row(2,1)]::comptype[]); -- fail
262
+ ERROR: value for domain dcomptypea violates check constraint "c1"
263
+ insert into dcomptable (d1[1].r) values(99);
264
+ insert into dcomptable (d1[1].r, d1[1].i) values(99, 100);
265
+ insert into dcomptable (d1[1].r, d1[1].i) values(100, 99); -- fail
266
+ ERROR: value for domain dcomptypea violates check constraint "c1"
267
+ update dcomptable set d1[1].r = d1[1].r + 1 where d1[1].i > 0; -- fail
268
+ ERROR: value for domain dcomptypea violates check constraint "c1"
269
+ update dcomptable set d1[1].r = d1[1].r - 1 where d1[1].i > 0;
270
+ select * from dcomptable;
271
+ d1
272
+ --------------------
273
+ {"(11,)","(,)"}
274
+ {"(99,)"}
275
+ {"(1,2)","(,)"}
276
+ {"(3,4)","(6,5)"}
277
+ {"(7,8)","(10,9)"}
278
+ {"(9,10)","(,)"}
279
+ {"(0,2)"}
280
+ {"(98,100)"}
281
+ (8 rows)
282
+
283
+ drop table dcomptable;
284
+ drop type comptype cascade;
285
+ NOTICE: drop cascades to type dcomptypea
286
+ -- Test not-null restrictions
185
287
create domain dnotnull varchar(15) NOT NULL;
186
288
create domain dnull varchar(15);
187
289
create domain dcheck varchar(15) NOT NULL CHECK (VALUE = 'a' OR VALUE = 'c' OR VALUE = 'd');
0 commit comments