1--
2-- Test domains.
3--
4
5-- Test Comment / Drop
6create domain domaindroptest int4;
7comment on domain domaindroptest is 'About to drop this..';
8
9create domain dependenttypetest domaindroptest;
10
11-- fail because of dependent type
12drop domain domaindroptest;
13
14drop domain domaindroptest cascade;
15
16-- this should fail because already gone
17drop domain domaindroptest cascade;
18
19
20-- Test domain input.
21
22-- Note: the point of checking both INSERT and COPY FROM is that INSERT
23-- exercises CoerceToDomain while COPY exercises domain_in.
24
25create domain domainvarchar varchar(5);
26create domain domainnumeric numeric(8,2);
27create domain domainint4 int4;
28create domain domaintext text;
29
30-- Test explicit coercions --- these should succeed (and truncate)
31SELECT cast('123456' as domainvarchar);
32SELECT cast('12345' as domainvarchar);
33
34-- Test tables using domains
35create table basictest
36           ( testint4 domainint4
37           , testtext domaintext
38           , testvarchar domainvarchar
39           , testnumeric domainnumeric
40           );
41
42INSERT INTO basictest values ('88', 'haha', 'short', '123.12');      -- Good
43INSERT INTO basictest values ('88', 'haha', 'short text', '123.12'); -- Bad varchar
44INSERT INTO basictest values ('88', 'haha', 'short', '123.1212');    -- Truncate numeric
45
46select * from basictest;
47
48-- check that domains inherit operations from base types
49select testtext || testvarchar as concat, testnumeric + 42 as sum
50from basictest;
51
52-- check that union/case/coalesce type resolution handles domains properly
53select coalesce(4::domainint4, 7) is of (int4) as t;
54select coalesce(4::domainint4, 7) is of (domainint4) as f;
55select coalesce(4::domainint4, 7::domainint4) is of (domainint4) as t;
56
57drop table basictest;
58drop domain domainvarchar restrict;
59drop domain domainnumeric restrict;
60drop domain domainint4 restrict;
61drop domain domaintext;
62
63
64-- Test domains over array types
65
66create domain domainint4arr int4[1];
67create domain domainchar4arr varchar(4)[2][3];
68
69create table domarrtest
70           ( testint4arr domainint4arr
71           , testchar4arr domainchar4arr
72            );
73INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"}}');
74INSERT INTO domarrtest values ('{{2,2},{2,2}}', '{{"a","b"}}');
75INSERT INTO domarrtest values ('{2,2}', '{{"a","b"},{"c","d"},{"e","f"}}');
76INSERT INTO domarrtest values ('{2,2}', '{{"a"},{"c"}}');
77INSERT INTO domarrtest values (NULL, '{{"a","b","c"},{"d","e","f"}}');
78INSERT INTO domarrtest values (NULL, '{{"toolong","b","c"},{"d","e","f"}}');
79INSERT INTO domarrtest (testint4arr[1], testint4arr[3]) values (11,22);
80select * from domarrtest;
81select testint4arr[1], testchar4arr[2:2] from domarrtest;
82select array_dims(testint4arr), array_dims(testchar4arr) from domarrtest;
83
84select * from domarrtest;
85
86update domarrtest set
87  testint4arr[1] = testint4arr[1] + 1,
88  testint4arr[3] = testint4arr[3] - 1
89where testchar4arr is null;
90
91select * from domarrtest where testchar4arr is null;
92
93drop table domarrtest;
94drop domain domainint4arr restrict;
95drop domain domainchar4arr restrict;
96
97create domain dia as int[];
98select '{1,2,3}'::dia;
99select array_dims('{1,2,3}'::dia);
100select pg_typeof('{1,2,3}'::dia);
101select pg_typeof('{1,2,3}'::dia || 42); -- should be int[] not dia
102drop domain dia;
103
104
105-- Test domains over composites
106
107create type comptype as (r float8, i float8);
108create domain dcomptype as comptype;
109create table dcomptable (d1 dcomptype unique);
110
111insert into dcomptable values (row(1,2)::dcomptype);
112insert into dcomptable values (row(3,4)::comptype);
113insert into dcomptable values (row(1,2)::dcomptype);  -- fail on uniqueness
114insert into dcomptable (d1.r) values(11);
115
116select * from dcomptable;
117select (d1).r, (d1).i, (d1).* from dcomptable;
118update dcomptable set d1.r = (d1).r + 1 where (d1).i > 0;
119select * from dcomptable;
120
121alter domain dcomptype add constraint c1 check ((value).r <= (value).i);
122alter domain dcomptype add constraint c2 check ((value).r > (value).i);  -- fail
123
124select row(2,1)::dcomptype;  -- fail
125insert into dcomptable values (row(1,2)::comptype);
126insert into dcomptable values (row(2,1)::comptype);  -- fail
127insert into dcomptable (d1.r) values(99);
128insert into dcomptable (d1.r, d1.i) values(99, 100);
129insert into dcomptable (d1.r, d1.i) values(100, 99);  -- fail
130update dcomptable set d1.r = (d1).r + 1 where (d1).i > 0;  -- fail
131update dcomptable set d1.r = (d1).r - 1, d1.i = (d1).i + 1 where (d1).i > 0;
132select * from dcomptable;
133
134explain (verbose, costs off)
135  update dcomptable set d1.r = (d1).r - 1, d1.i = (d1).i + 1 where (d1).i > 0;
136create rule silly as on delete to dcomptable do instead
137  update dcomptable set d1.r = (d1).r - 1, d1.i = (d1).i + 1 where (d1).i > 0;
138\d+ dcomptable
139
140drop table dcomptable;
141drop type comptype cascade;
142
143
144-- check altering and dropping columns used by domain constraints
145create type comptype as (r float8, i float8);
146create domain dcomptype as comptype;
147alter domain dcomptype add constraint c1 check ((value).r > 0);
148comment on constraint c1 on domain dcomptype is 'random commentary';
149
150select row(0,1)::dcomptype;  -- fail
151
152alter type comptype alter attribute r type varchar;  -- fail
153alter type comptype alter attribute r type bigint;
154
155alter type comptype drop attribute r;  -- fail
156alter type comptype drop attribute i;
157
158select conname, obj_description(oid, 'pg_constraint') from pg_constraint
159  where contypid = 'dcomptype'::regtype;  -- check comment is still there
160
161drop type comptype cascade;
162
163
164-- Test domains over arrays of composite
165
166create type comptype as (r float8, i float8);
167create domain dcomptypea as comptype[];
168create table dcomptable (d1 dcomptypea unique);
169
170insert into dcomptable values (array[row(1,2)]::dcomptypea);
171insert into dcomptable values (array[row(3,4), row(5,6)]::comptype[]);
172insert into dcomptable values (array[row(7,8)::comptype, row(9,10)::comptype]);
173insert into dcomptable values (array[row(1,2)]::dcomptypea);  -- fail on uniqueness
174insert into dcomptable (d1[1]) values(row(9,10));
175insert into dcomptable (d1[1].r) values(11);
176
177select * from dcomptable;
178select d1[2], d1[1].r, d1[1].i from dcomptable;
179update dcomptable set d1[2] = row(d1[2].i, d1[2].r);
180select * from dcomptable;
181update dcomptable set d1[1].r = d1[1].r + 1 where d1[1].i > 0;
182select * from dcomptable;
183
184alter domain dcomptypea add constraint c1 check (value[1].r <= value[1].i);
185alter domain dcomptypea add constraint c2 check (value[1].r > value[1].i);  -- fail
186
187select array[row(2,1)]::dcomptypea;  -- fail
188insert into dcomptable values (array[row(1,2)]::comptype[]);
189insert into dcomptable values (array[row(2,1)]::comptype[]);  -- fail
190insert into dcomptable (d1[1].r) values(99);
191insert into dcomptable (d1[1].r, d1[1].i) values(99, 100);
192insert into dcomptable (d1[1].r, d1[1].i) values(100, 99);  -- fail
193update dcomptable set d1[1].r = d1[1].r + 1 where d1[1].i > 0;  -- fail
194update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1
195  where d1[1].i > 0;
196select * from dcomptable;
197
198explain (verbose, costs off)
199  update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1
200    where d1[1].i > 0;
201create rule silly as on delete to dcomptable do instead
202  update dcomptable set d1[1].r = d1[1].r - 1, d1[1].i = d1[1].i + 1
203    where d1[1].i > 0;
204\d+ dcomptable
205
206drop table dcomptable;
207drop type comptype cascade;
208
209
210-- Test arrays over domains
211
212create domain posint as int check (value > 0);
213
214create table pitable (f1 posint[]);
215insert into pitable values(array[42]);
216insert into pitable values(array[-1]);  -- fail
217insert into pitable values('{0}');  -- fail
218update pitable set f1[1] = f1[1] + 1;
219update pitable set f1[1] = 0;  -- fail
220select * from pitable;
221drop table pitable;
222
223create domain vc4 as varchar(4);
224create table vc4table (f1 vc4[]);
225insert into vc4table values(array['too long']);  -- fail
226insert into vc4table values(array['too long']::vc4[]);  -- cast truncates
227select * from vc4table;
228drop table vc4table;
229drop type vc4;
230
231-- You can sort of fake arrays-of-arrays by putting a domain in between
232create domain dposinta as posint[];
233create table dposintatable (f1 dposinta[]);
234insert into dposintatable values(array[array[42]]);  -- fail
235insert into dposintatable values(array[array[42]::posint[]]); -- still fail
236insert into dposintatable values(array[array[42]::dposinta]); -- but this works
237select f1, f1[1], (f1[1])[1] from dposintatable;
238select pg_typeof(f1) from dposintatable;
239select pg_typeof(f1[1]) from dposintatable;
240select pg_typeof(f1[1][1]) from dposintatable;
241select pg_typeof((f1[1])[1]) from dposintatable;
242update dposintatable set f1[2] = array[99];
243select f1, f1[1], (f1[2])[1] from dposintatable;
244-- it'd be nice if you could do something like this, but for now you can't:
245update dposintatable set f1[2][1] = array[97];
246-- maybe someday we can make this syntax work:
247update dposintatable set (f1[2])[1] = array[98];
248
249drop table dposintatable;
250drop domain posint cascade;
251
252
253-- Test not-null restrictions
254
255create domain dnotnull varchar(15) NOT NULL;
256create domain dnull    varchar(15);
257create domain dcheck   varchar(15) NOT NULL CHECK (VALUE = 'a' OR VALUE = 'c' OR VALUE = 'd');
258
259create table nulltest
260           ( col1 dnotnull
261           , col2 dnotnull NULL  -- NOT NULL in the domain cannot be overridden
262           , col3 dnull    NOT NULL
263           , col4 dnull
264           , col5 dcheck CHECK (col5 IN ('c', 'd'))
265           );
266INSERT INTO nulltest DEFAULT VALUES;
267INSERT INTO nulltest values ('a', 'b', 'c', 'd', 'c');  -- Good
268insert into nulltest values ('a', 'b', 'c', 'd', NULL);
269insert into nulltest values ('a', 'b', 'c', 'd', 'a');
270INSERT INTO nulltest values (NULL, 'b', 'c', 'd', 'd');
271INSERT INTO nulltest values ('a', NULL, 'c', 'd', 'c');
272INSERT INTO nulltest values ('a', 'b', NULL, 'd', 'c');
273INSERT INTO nulltest values ('a', 'b', 'c', NULL, 'd'); -- Good
274
275select * from nulltest;
276
277-- Test out coerced (casted) constraints
278SELECT cast('1' as dnotnull);
279SELECT cast(NULL as dnotnull); -- fail
280SELECT cast(cast(NULL as dnull) as dnotnull); -- fail
281SELECT cast(col4 as dnotnull) from nulltest; -- fail
282
283-- cleanup
284drop table nulltest;
285drop domain dnotnull restrict;
286drop domain dnull restrict;
287drop domain dcheck restrict;
288
289
290create domain ddef1 int4 DEFAULT 3;
291create domain ddef2 oid DEFAULT '12';
292-- Type mixing, function returns int8
293create domain ddef3 text DEFAULT 5;
294create sequence ddef4_seq;
295create domain ddef4 int4 DEFAULT nextval('ddef4_seq');
296create domain ddef5 numeric(8,2) NOT NULL DEFAULT '12.12';
297
298create table defaulttest
299            ( col1 ddef1
300            , col2 ddef2
301            , col3 ddef3
302            , col4 ddef4 PRIMARY KEY
303            , col5 ddef1 NOT NULL DEFAULT NULL
304            , col6 ddef2 DEFAULT '88'
305            , col7 ddef4 DEFAULT 8000
306            , col8 ddef5
307            );
308insert into defaulttest(col4) values(0); -- fails, col5 defaults to null
309alter table defaulttest alter column col5 drop default;
310insert into defaulttest default values; -- succeeds, inserts domain default
311-- We used to treat SET DEFAULT NULL as equivalent to DROP DEFAULT; wrong
312alter table defaulttest alter column col5 set default null;
313insert into defaulttest(col4) values(0); -- fails
314alter table defaulttest alter column col5 drop default;
315insert into defaulttest default values;
316insert into defaulttest default values;
317
318select * from defaulttest;
319
320drop table defaulttest cascade;
321
322-- Test ALTER DOMAIN .. NOT NULL
323create domain dnotnulltest integer;
324create table domnotnull
325( col1 dnotnulltest
326, col2 dnotnulltest
327);
328
329insert into domnotnull default values;
330alter domain dnotnulltest set not null; -- fails
331
332update domnotnull set col1 = 5;
333alter domain dnotnulltest set not null; -- fails
334
335update domnotnull set col2 = 6;
336
337alter domain dnotnulltest set not null;
338
339update domnotnull set col1 = null; -- fails
340
341alter domain dnotnulltest drop not null;
342
343update domnotnull set col1 = null;
344
345drop domain dnotnulltest cascade;
346
347-- Test ALTER DOMAIN .. DEFAULT ..
348create table domdeftest (col1 ddef1);
349
350insert into domdeftest default values;
351select * from domdeftest;
352
353alter domain ddef1 set default '42';
354insert into domdeftest default values;
355select * from domdeftest;
356
357alter domain ddef1 drop default;
358insert into domdeftest default values;
359select * from domdeftest;
360
361drop table domdeftest;
362
363-- Test ALTER DOMAIN .. CONSTRAINT ..
364create domain con as integer;
365create table domcontest (col1 con);
366
367insert into domcontest values (1);
368insert into domcontest values (2);
369alter domain con add constraint t check (VALUE < 1); -- fails
370
371alter domain con add constraint t check (VALUE < 34);
372alter domain con add check (VALUE > 0);
373
374insert into domcontest values (-5); -- fails
375insert into domcontest values (42); -- fails
376insert into domcontest values (5);
377
378alter domain con drop constraint t;
379insert into domcontest values (-5); --fails
380insert into domcontest values (42);
381
382alter domain con drop constraint nonexistent;
383alter domain con drop constraint if exists nonexistent;
384
385-- Test ALTER DOMAIN .. CONSTRAINT .. NOT VALID
386create domain things AS INT;
387CREATE TABLE thethings (stuff things);
388INSERT INTO thethings (stuff) VALUES (55);
389ALTER DOMAIN things ADD CONSTRAINT meow CHECK (VALUE < 11);
390ALTER DOMAIN things ADD CONSTRAINT meow CHECK (VALUE < 11) NOT VALID;
391ALTER DOMAIN things VALIDATE CONSTRAINT meow;
392UPDATE thethings SET stuff = 10;
393ALTER DOMAIN things VALIDATE CONSTRAINT meow;
394
395-- Confirm ALTER DOMAIN with RULES.
396create table domtab (col1 integer);
397create domain dom as integer;
398create view domview as select cast(col1 as dom) from domtab;
399insert into domtab (col1) values (null);
400insert into domtab (col1) values (5);
401select * from domview;
402
403alter domain dom set not null;
404select * from domview; -- fail
405
406alter domain dom drop not null;
407select * from domview;
408
409alter domain dom add constraint domchkgt6 check(value > 6);
410select * from domview; --fail
411
412alter domain dom drop constraint domchkgt6 restrict;
413select * from domview;
414
415-- cleanup
416drop domain ddef1 restrict;
417drop domain ddef2 restrict;
418drop domain ddef3 restrict;
419drop domain ddef4 restrict;
420drop domain ddef5 restrict;
421drop sequence ddef4_seq;
422
423-- Test domains over domains
424create domain vchar4 varchar(4);
425create domain dinter vchar4 check (substring(VALUE, 1, 1) = 'x');
426create domain dtop dinter check (substring(VALUE, 2, 1) = '1');
427
428select 'x123'::dtop;
429select 'x1234'::dtop; -- explicit coercion should truncate
430select 'y1234'::dtop; -- fail
431select 'y123'::dtop; -- fail
432select 'yz23'::dtop; -- fail
433select 'xz23'::dtop; -- fail
434
435create temp table dtest(f1 dtop);
436
437insert into dtest values('x123');
438insert into dtest values('x1234'); -- fail, implicit coercion
439insert into dtest values('y1234'); -- fail, implicit coercion
440insert into dtest values('y123'); -- fail
441insert into dtest values('yz23'); -- fail
442insert into dtest values('xz23'); -- fail
443
444drop table dtest;
445drop domain vchar4 cascade;
446
447-- Make sure that constraints of newly-added domain columns are
448-- enforced correctly, even if there's no default value for the new
449-- column. Per bug #1433
450create domain str_domain as text not null;
451
452create table domain_test (a int, b int);
453
454insert into domain_test values (1, 2);
455insert into domain_test values (1, 2);
456
457-- should fail
458alter table domain_test add column c str_domain;
459
460create domain str_domain2 as text check (value <> 'foo') default 'foo';
461
462-- should fail
463alter table domain_test add column d str_domain2;
464
465-- Check that domain constraints on prepared statement parameters of
466-- unknown type are enforced correctly.
467create domain pos_int as int4 check (value > 0) not null;
468prepare s1 as select $1::pos_int = 10 as "is_ten";
469
470execute s1(10);
471execute s1(0); -- should fail
472execute s1(NULL); -- should fail
473
474-- Check that domain constraints on plpgsql function parameters, results,
475-- and local variables are enforced correctly.
476
477create function doubledecrement(p1 pos_int) returns pos_int as $$
478declare v pos_int;
479begin
480    return p1;
481end$$ language plpgsql;
482
483select doubledecrement(3); -- fail because of implicit null assignment
484
485create or replace function doubledecrement(p1 pos_int) returns pos_int as $$
486declare v pos_int := 0;
487begin
488    return p1;
489end$$ language plpgsql;
490
491select doubledecrement(3); -- fail at initialization assignment
492
493create or replace function doubledecrement(p1 pos_int) returns pos_int as $$
494declare v pos_int := 1;
495begin
496    v := p1 - 1;
497    return v - 1;
498end$$ language plpgsql;
499
500select doubledecrement(null); -- fail before call
501select doubledecrement(0); -- fail before call
502select doubledecrement(1); -- fail at assignment to v
503select doubledecrement(2); -- fail at return
504select doubledecrement(3); -- good
505
506-- Check that ALTER DOMAIN tests columns of derived types
507
508create domain posint as int4;
509
510-- Currently, this doesn't work for composite types, but verify it complains
511create type ddtest1 as (f1 posint);
512create table ddtest2(f1 ddtest1);
513insert into ddtest2 values(row(-1));
514alter domain posint add constraint c1 check(value >= 0);
515drop table ddtest2;
516
517-- Likewise for domains within arrays of composite
518create table ddtest2(f1 ddtest1[]);
519insert into ddtest2 values('{(-1)}');
520alter domain posint add constraint c1 check(value >= 0);
521drop table ddtest2;
522
523-- Likewise for domains within domains over composite
524create domain ddtest1d as ddtest1;
525create table ddtest2(f1 ddtest1d);
526insert into ddtest2 values('(-1)');
527alter domain posint add constraint c1 check(value >= 0);
528drop table ddtest2;
529drop domain ddtest1d;
530
531-- Likewise for domains within domains over array of composite
532create domain ddtest1d as ddtest1[];
533create table ddtest2(f1 ddtest1d);
534insert into ddtest2 values('{(-1)}');
535alter domain posint add constraint c1 check(value >= 0);
536drop table ddtest2;
537drop domain ddtest1d;
538
539-- Doesn't work for ranges, either
540create type rposint as range (subtype = posint);
541create table ddtest2(f1 rposint);
542insert into ddtest2 values('(-1,3]');
543alter domain posint add constraint c1 check(value >= 0);
544drop table ddtest2;
545drop type rposint;
546
547alter domain posint add constraint c1 check(value >= 0);
548
549create domain posint2 as posint check (value % 2 = 0);
550create table ddtest2(f1 posint2);
551insert into ddtest2 values(11); -- fail
552insert into ddtest2 values(-2); -- fail
553insert into ddtest2 values(2);
554
555alter domain posint add constraint c2 check(value >= 10); -- fail
556alter domain posint add constraint c2 check(value > 0); -- OK
557
558drop table ddtest2;
559drop type ddtest1;
560drop domain posint cascade;
561
562--
563-- Check enforcement of domain-related typmod in plpgsql (bug #5717)
564--
565
566create or replace function array_elem_check(numeric) returns numeric as $$
567declare
568  x numeric(4,2)[1];
569begin
570  x[1] := $1;
571  return x[1];
572end$$ language plpgsql;
573
574select array_elem_check(121.00);
575select array_elem_check(1.23456);
576
577create domain mynums as numeric(4,2)[1];
578
579create or replace function array_elem_check(numeric) returns numeric as $$
580declare
581  x mynums;
582begin
583  x[1] := $1;
584  return x[1];
585end$$ language plpgsql;
586
587select array_elem_check(121.00);
588select array_elem_check(1.23456);
589
590create domain mynums2 as mynums;
591
592create or replace function array_elem_check(numeric) returns numeric as $$
593declare
594  x mynums2;
595begin
596  x[1] := $1;
597  return x[1];
598end$$ language plpgsql;
599
600select array_elem_check(121.00);
601select array_elem_check(1.23456);
602
603drop function array_elem_check(numeric);
604
605--
606-- Check enforcement of array-level domain constraints
607--
608
609create domain orderedpair as int[2] check (value[1] < value[2]);
610
611select array[1,2]::orderedpair;
612select array[2,1]::orderedpair;  -- fail
613
614create temp table op (f1 orderedpair);
615insert into op values (array[1,2]);
616insert into op values (array[2,1]);  -- fail
617
618update op set f1[2] = 3;
619update op set f1[2] = 0;  -- fail
620select * from op;
621
622create or replace function array_elem_check(int) returns int as $$
623declare
624  x orderedpair := '{1,2}';
625begin
626  x[2] := $1;
627  return x[2];
628end$$ language plpgsql;
629
630select array_elem_check(3);
631select array_elem_check(-1);
632
633drop function array_elem_check(int);
634
635--
636-- Check enforcement of changing constraints in plpgsql
637--
638
639create domain di as int;
640
641create function dom_check(int) returns di as $$
642declare d di;
643begin
644  d := $1::di;
645  return d;
646end
647$$ language plpgsql immutable;
648
649select dom_check(0);
650
651alter domain di add constraint pos check (value > 0);
652
653select dom_check(0); -- fail
654
655alter domain di drop constraint pos;
656
657select dom_check(0);
658
659-- implicit cast during assignment is a separate code path, test that too
660
661create or replace function dom_check(int) returns di as $$
662declare d di;
663begin
664  d := $1;
665  return d;
666end
667$$ language plpgsql immutable;
668
669select dom_check(0);
670
671alter domain di add constraint pos check (value > 0);
672
673select dom_check(0); -- fail
674
675alter domain di drop constraint pos;
676
677select dom_check(0);
678
679drop function dom_check(int);
680
681drop domain di;
682
683--
684-- Check use of a (non-inline-able) SQL function in a domain constraint;
685-- this has caused issues in the past
686--
687
688create function sql_is_distinct_from(anyelement, anyelement)
689returns boolean language sql
690as 'select $1 is distinct from $2 limit 1';
691
692create domain inotnull int
693  check (sql_is_distinct_from(value, null));
694
695select 1::inotnull;
696select null::inotnull;
697
698create table dom_table (x inotnull);
699insert into dom_table values ('1');
700insert into dom_table values (1);
701insert into dom_table values (null);
702
703drop table dom_table;
704drop domain inotnull;
705drop function sql_is_distinct_from(anyelement, anyelement);
706
707--
708-- Renaming
709--
710
711create domain testdomain1 as int;
712alter domain testdomain1 rename to testdomain2;
713alter type testdomain2 rename to testdomain3;  -- alter type also works
714drop domain testdomain3;
715
716
717--
718-- Renaming domain constraints
719--
720
721create domain testdomain1 as int constraint unsigned check (value > 0);
722alter domain testdomain1 rename constraint unsigned to unsigned_foo;
723alter domain testdomain1 drop constraint unsigned_foo;
724drop domain testdomain1;
725