mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Change syntax of new CHECK NO INHERIT constraints
The initially implemented syntax, "CHECK NO INHERIT (expr)" was not deemed very good, so switch to "CHECK (expr) NO INHERIT" instead. This way it looks similar to SQL-standards compliant constraint attribute. Backport to 9.2 where the new syntax and feature was introduced. Per discussion.
This commit is contained in:
@ -101,6 +101,7 @@ typedef struct PrivTarget
|
||||
#define CAS_INITIALLY_IMMEDIATE 0x04
|
||||
#define CAS_INITIALLY_DEFERRED 0x08
|
||||
#define CAS_NOT_VALID 0x10
|
||||
#define CAS_NO_INHERIT 0x20
|
||||
|
||||
|
||||
#define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
|
||||
@ -144,7 +145,7 @@ static void SplitColQualList(List *qualList,
|
||||
core_yyscan_t yyscanner);
|
||||
static void processCASbits(int cas_bits, int location, const char *constrType,
|
||||
bool *deferrable, bool *initdeferred, bool *not_valid,
|
||||
core_yyscan_t yyscanner);
|
||||
bool *no_inherit, core_yyscan_t yyscanner);
|
||||
|
||||
%}
|
||||
|
||||
@ -2709,13 +2710,13 @@ ColConstraintElem:
|
||||
n->indexspace = $4;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| CHECK opt_no_inherit '(' a_expr ')'
|
||||
| CHECK '(' a_expr ')' opt_no_inherit
|
||||
{
|
||||
Constraint *n = makeNode(Constraint);
|
||||
n->contype = CONSTR_CHECK;
|
||||
n->location = @1;
|
||||
n->is_no_inherit = $2;
|
||||
n->raw_expr = $4;
|
||||
n->is_no_inherit = $5;
|
||||
n->raw_expr = $3;
|
||||
n->cooked_expr = NULL;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
@ -2755,10 +2756,10 @@ ColConstraintElem:
|
||||
* combinations.
|
||||
*
|
||||
* See also ConstraintAttributeSpec, which can be used in places where
|
||||
* there is no parsing conflict. (Note: currently, NOT VALID is an allowed
|
||||
* clause in ConstraintAttributeSpec, but not here. Someday we might need
|
||||
* to allow it here too, but for the moment it doesn't seem useful in the
|
||||
* statements that use ConstraintAttr.)
|
||||
* there is no parsing conflict. (Note: currently, NOT VALID and NO INHERIT
|
||||
* are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
|
||||
* might need to allow them here too, but for the moment it doesn't seem
|
||||
* useful in the statements that use ConstraintAttr.)
|
||||
*/
|
||||
ConstraintAttr:
|
||||
DEFERRABLE
|
||||
@ -2835,17 +2836,16 @@ TableConstraint:
|
||||
;
|
||||
|
||||
ConstraintElem:
|
||||
CHECK opt_no_inherit '(' a_expr ')' ConstraintAttributeSpec
|
||||
CHECK '(' a_expr ')' ConstraintAttributeSpec
|
||||
{
|
||||
Constraint *n = makeNode(Constraint);
|
||||
n->contype = CONSTR_CHECK;
|
||||
n->location = @1;
|
||||
n->is_no_inherit = $2;
|
||||
n->raw_expr = $4;
|
||||
n->raw_expr = $3;
|
||||
n->cooked_expr = NULL;
|
||||
processCASbits($6, @6, "CHECK",
|
||||
processCASbits($5, @5, "CHECK",
|
||||
NULL, NULL, &n->skip_validation,
|
||||
yyscanner);
|
||||
&n->is_no_inherit, yyscanner);
|
||||
n->initially_valid = !n->skip_validation;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
@ -2861,7 +2861,7 @@ ConstraintElem:
|
||||
n->indexspace = $6;
|
||||
processCASbits($7, @7, "UNIQUE",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
yyscanner);
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| UNIQUE ExistingIndex ConstraintAttributeSpec
|
||||
@ -2875,7 +2875,7 @@ ConstraintElem:
|
||||
n->indexspace = NULL;
|
||||
processCASbits($3, @3, "UNIQUE",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
yyscanner);
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| PRIMARY KEY '(' columnList ')' opt_definition OptConsTableSpace
|
||||
@ -2890,7 +2890,7 @@ ConstraintElem:
|
||||
n->indexspace = $7;
|
||||
processCASbits($8, @8, "PRIMARY KEY",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
yyscanner);
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| PRIMARY KEY ExistingIndex ConstraintAttributeSpec
|
||||
@ -2904,7 +2904,7 @@ ConstraintElem:
|
||||
n->indexspace = NULL;
|
||||
processCASbits($4, @4, "PRIMARY KEY",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
yyscanner);
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
|
||||
@ -2922,7 +2922,7 @@ ConstraintElem:
|
||||
n->where_clause = $8;
|
||||
processCASbits($9, @9, "EXCLUDE",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
yyscanner);
|
||||
NULL, yyscanner);
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
| FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
|
||||
@ -2939,7 +2939,7 @@ ConstraintElem:
|
||||
n->fk_del_action = (char) ($10 & 0xFF);
|
||||
processCASbits($11, @11, "FOREIGN KEY",
|
||||
&n->deferrable, &n->initdeferred,
|
||||
&n->skip_validation,
|
||||
&n->skip_validation, NULL,
|
||||
yyscanner);
|
||||
n->initially_valid = !n->skip_validation;
|
||||
$$ = (Node *)n;
|
||||
@ -4133,7 +4133,7 @@ CreateTrigStmt:
|
||||
n->isconstraint = TRUE;
|
||||
processCASbits($10, @10, "TRIGGER",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
yyscanner);
|
||||
NULL, yyscanner);
|
||||
n->constrrel = $9;
|
||||
$$ = (Node *)n;
|
||||
}
|
||||
@ -4270,6 +4270,7 @@ ConstraintAttributeElem:
|
||||
| INITIALLY IMMEDIATE { $$ = CAS_INITIALLY_IMMEDIATE; }
|
||||
| INITIALLY DEFERRED { $$ = CAS_INITIALLY_DEFERRED; }
|
||||
| NOT VALID { $$ = CAS_NOT_VALID; }
|
||||
| NO INHERIT { $$ = CAS_NO_INHERIT; }
|
||||
;
|
||||
|
||||
|
||||
@ -4386,7 +4387,7 @@ CreateAssertStmt:
|
||||
n->isconstraint = TRUE;
|
||||
processCASbits($8, @8, "ASSERTION",
|
||||
&n->deferrable, &n->initdeferred, NULL,
|
||||
yyscanner);
|
||||
NULL, yyscanner);
|
||||
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
@ -13380,7 +13381,7 @@ SplitColQualList(List *qualList,
|
||||
static void
|
||||
processCASbits(int cas_bits, int location, const char *constrType,
|
||||
bool *deferrable, bool *initdeferred, bool *not_valid,
|
||||
core_yyscan_t yyscanner)
|
||||
bool *no_inherit, core_yyscan_t yyscanner)
|
||||
{
|
||||
/* defaults */
|
||||
if (deferrable)
|
||||
@ -13428,6 +13429,19 @@ processCASbits(int cas_bits, int location, const char *constrType,
|
||||
constrType),
|
||||
parser_errposition(location)));
|
||||
}
|
||||
|
||||
if (cas_bits & CAS_NO_INHERIT)
|
||||
{
|
||||
if (no_inherit)
|
||||
*no_inherit = true;
|
||||
else
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
/* translator: %s is CHECK, UNIQUE, or similar */
|
||||
errmsg("%s constraints cannot be marked NO INHERIT",
|
||||
constrType),
|
||||
parser_errposition(location)));
|
||||
}
|
||||
}
|
||||
|
||||
/* parser_init()
|
||||
|
Reference in New Issue
Block a user