diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 28f4e11e30ff..441fee8226eb 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -4499,8 +4499,28 @@ DomainConstraintElem: n->raw_expr = $3; n->cooked_expr = NULL; processCASbits($5, @5, "CHECK", - NULL, NULL, NULL, &n->skip_validation, - &n->is_no_inherit, yyscanner); + &n->deferrable, &n->initdeferred, &n->is_enforced, + &n->skip_validation, &n->is_no_inherit, yyscanner); + + if ($5 & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE | CAS_INITIALLY_IMMEDIATE | + CAS_INITIALLY_DEFERRED)) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("specifying constraint deferrability not supported for domains"), + parser_errposition(@5)); + + if ($5 & (CAS_NOT_ENFORCED | CAS_ENFORCED)) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("specifying constraint enforceability not supported for domains"), + parser_errposition(@5)); + + if (n->is_no_inherit) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("check constraints for domains cannot be marked %s", "NO INHERIT"), + parser_errposition(@5)); + n->is_enforced = true; n->initially_valid = !n->skip_validation; $$ = (Node *) n; @@ -4514,8 +4534,33 @@ DomainConstraintElem: n->keys = list_make1(makeString("value")); /* no NOT VALID, NO INHERIT support */ processCASbits($3, @3, "NOT NULL", - NULL, NULL, NULL, - NULL, NULL, yyscanner); + &n->deferrable, &n->initdeferred, &n->is_enforced, + &n->skip_validation, &n->is_no_inherit, yyscanner); + if (($3 & CAS_NOT_VALID) != 0) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("not-null constraints on domains cannot be marked %s", "NOT VALID"), + parser_errposition(@3)); + + if ($3 & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE | CAS_INITIALLY_IMMEDIATE | + CAS_INITIALLY_DEFERRED)) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("specifying constraint deferrability not supported for domains"), + parser_errposition(@3)); + + if ($3 & (CAS_NOT_ENFORCED | CAS_ENFORCED)) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("specifying constraint enforceability not supported for domains"), + parser_errposition(@3)); + + if (n->is_no_inherit) + ereport(ERROR, + errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("not-null constraints on domains cannot be marked %s", "NO INHERIT"), + parser_errposition(@3)); + n->initially_valid = true; $$ = (Node *) n; } diff --git a/src/test/regress/expected/domain.out b/src/test/regress/expected/domain.out index 62a48a523a2d..357dac1f5554 100644 --- a/src/test/regress/expected/domain.out +++ b/src/test/regress/expected/domain.out @@ -68,6 +68,44 @@ create domain d_fail as int4 constraint cc check (values > 1) deferrable; ERROR: specifying constraint deferrability not supported for domains LINE 1: ...n d_fail as int4 constraint cc check (values > 1) deferrable... ^ +create domain d_int as int4; +alter domain d_int add constraint nn not null not valid; +ERROR: not-null constraints on domains cannot be marked NOT VALID +LINE 1: alter domain d_int add constraint nn not null not valid; + ^ +alter domain d_int add constraint nn not null no inherit; +ERROR: not-null constraints on domains cannot be marked NO INHERIT +LINE 1: alter domain d_int add constraint nn not null no inherit; + ^ +alter domain d_int add constraint nn not null not enforced; +ERROR: specifying constraint enforceability not supported for domains +LINE 1: alter domain d_int add constraint nn not null not enforced; + ^ +alter domain d_int add constraint nn not null not deferrable initially immediate; +ERROR: specifying constraint deferrability not supported for domains +LINE 1: alter domain d_int add constraint nn not null not deferrable... + ^ +alter domain d_int add constraint cc check(value > 1) no inherit; +ERROR: check constraints for domains cannot be marked NO INHERIT +LINE 1: ...r domain d_int add constraint cc check(value > 1) no inherit... + ^ +alter domain d_int add constraint cc check(value > 1) not enforced; +ERROR: specifying constraint enforceability not supported for domains +LINE 1: ...r domain d_int add constraint cc check(value > 1) not enforc... + ^ +alter domain d_int add constraint cc check(value > 1) enforced; +ERROR: specifying constraint enforceability not supported for domains +LINE 1: ...er domain d_int add constraint cc check(value > 1) enforced; + ^ +alter domain d_int add constraint cc check(value > 1) not deferrable initially immediate; +ERROR: specifying constraint deferrability not supported for domains +LINE 1: ...r domain d_int add constraint cc check(value > 1) not deferr... + ^ +alter domain d_int add constraint cc check(value > 1) deferrable initially deferred; +ERROR: specifying constraint deferrability not supported for domains +LINE 1: ...r domain d_int add constraint cc check(value > 1) deferrable... + ^ +drop domain d_int; -- Test domain input. -- Note: the point of checking both INSERT and COPY FROM is that INSERT -- exercises CoerceToDomain while COPY exercises domain_in. @@ -1369,11 +1407,11 @@ LINE 1: ...S int CONSTRAINT the_constraint CHECK (value > 0) NOT ENFORC... CREATE DOMAIN constraint_enforced_dom AS int; -- XXX misleading error messages ALTER DOMAIN constraint_enforced_dom ADD CONSTRAINT the_constraint CHECK (value > 0) ENFORCED; -ERROR: CHECK constraints cannot be marked ENFORCED +ERROR: specifying constraint enforceability not supported for domains LINE 1: ...om ADD CONSTRAINT the_constraint CHECK (value > 0) ENFORCED; ^ ALTER DOMAIN constraint_enforced_dom ADD CONSTRAINT the_constraint CHECK (value > 0) NOT ENFORCED; -ERROR: CHECK constraints cannot be marked NOT ENFORCED +ERROR: specifying constraint enforceability not supported for domains LINE 1: ...m ADD CONSTRAINT the_constraint CHECK (value > 0) NOT ENFORC... ^ DROP DOMAIN constraint_enforced_dom; diff --git a/src/test/regress/sql/domain.sql b/src/test/regress/sql/domain.sql index b8f5a6397121..b0c13a75e3ab 100644 --- a/src/test/regress/sql/domain.sql +++ b/src/test/regress/sql/domain.sql @@ -31,6 +31,18 @@ create domain d_fail as int4 constraint cc generated by default as identity; create domain d_fail as int4 constraint cc check (values > 1) no inherit; create domain d_fail as int4 constraint cc check (values > 1) deferrable; +create domain d_int as int4; +alter domain d_int add constraint nn not null not valid; +alter domain d_int add constraint nn not null no inherit; +alter domain d_int add constraint nn not null not enforced; +alter domain d_int add constraint nn not null not deferrable initially immediate; +alter domain d_int add constraint cc check(value > 1) no inherit; +alter domain d_int add constraint cc check(value > 1) not enforced; +alter domain d_int add constraint cc check(value > 1) enforced; +alter domain d_int add constraint cc check(value > 1) not deferrable initially immediate; +alter domain d_int add constraint cc check(value > 1) deferrable initially deferred; +drop domain d_int; + -- Test domain input. -- Note: the point of checking both INSERT and COPY FROM is that INSERT