File tree Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Expand file tree Collapse file tree 3 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -939,11 +939,19 @@ DefineDomain(ParseState *pstate, CreateDomainStmt *stmt)
939
939
break ;
940
940
941
941
case CONSTR_NOTNULL :
942
- if (nullDefined && !typNotNull )
942
+ if (nullDefined )
943
+ {
944
+ if (!typNotNull )
945
+ ereport (ERROR ,
946
+ errcode (ERRCODE_SYNTAX_ERROR ),
947
+ errmsg ("conflicting NULL/NOT NULL constraints" ),
948
+ parser_errposition (pstate , constr -> location ));
949
+
943
950
ereport (ERROR ,
944
- errcode (ERRCODE_SYNTAX_ERROR ),
945
- errmsg ("conflicting NULL/ NOT NULL constraints " ),
951
+ errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
952
+ errmsg ("redundant NOT NULL constraint definition " ),
946
953
parser_errposition (pstate , constr -> location ));
954
+ }
947
955
if (constr -> is_no_inherit )
948
956
ereport (ERROR ,
949
957
errcode (ERRCODE_INVALID_OBJECT_DEFINITION ),
Original file line number Diff line number Diff line change @@ -1019,6 +1019,11 @@ insert into domain_test values (1, 2);
1019
1019
-- should fail
1020
1020
alter table domain_test add column c str_domain;
1021
1021
ERROR: domain str_domain does not allow null values
1022
+ -- disallow duplicated not-null constraints
1023
+ create domain int_domain1 as int constraint nn1 not null constraint nn2 not null;
1024
+ ERROR: redundant NOT NULL constraint definition
1025
+ LINE 1: ...domain int_domain1 as int constraint nn1 not null constraint...
1026
+ ^
1022
1027
create domain str_domain2 as text check (value <> 'foo') default 'foo';
1023
1028
-- should fail
1024
1029
alter table domain_test add column d str_domain2;
Original file line number Diff line number Diff line change @@ -602,6 +602,9 @@ insert into domain_test values (1, 2);
602
602
-- should fail
603
603
alter table domain_test add column c str_domain;
604
604
605
+ -- disallow duplicated not-null constraints
606
+ create domain int_domain1 as int constraint nn1 not null constraint nn2 not null ;
607
+
605
608
create domain str_domain2 as text check (value <> ' foo' ) default ' foo' ;
606
609
607
610
-- should fail
You can’t perform that action at this time.
0 commit comments