summaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2012-04-20 23:46:20 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2012-04-20 23:56:57 -0300
commit09ff76fcdb275769ac4d1a45a67416735613d04b (patch)
tree15d86c29de778477258b9d43128d8ed23ced6479 /src/backend/parser
parent1f0363001166ef6a43619846e44cfb9dbe7335ed (diff)
Recast "ONLY" column CHECK constraints as NO INHERIT
The original syntax wasn't universally loved, and it didn't allow its usage in CREATE TABLE, only ALTER TABLE. It now works everywhere, and it also allows using ALTER TABLE ONLY to add an uninherited CHECK constraint, per discussion. The pg_constraint column has accordingly been renamed connoinherit. This commit partly reverts some of the changes in 61d81bd28dbec65a6b144e0cd3d0bfe25913c3ac, particularly some pg_dump and psql bits, because now pg_get_constraintdef includes the necessary NO INHERIT within the constraint definition. Author: Nikhil Sontakke Some tweaks by me
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index ae1658a4ffe..a289d4bd148 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -420,7 +420,7 @@ static void processCASbits(int cas_bits, int location, const char *constrType,
%type <str> character
%type <str> extract_arg
%type <str> opt_charset
-%type <boolean> opt_varying opt_timezone
+%type <boolean> opt_varying opt_timezone opt_no_inherit
%type <ival> Iconst SignedIconst
%type <str> Sconst comment_text notify_payload
@@ -2685,12 +2685,13 @@ ColConstraintElem:
n->indexspace = $4;
$$ = (Node *)n;
}
- | CHECK '(' a_expr ')'
+ | CHECK opt_no_inherit '(' a_expr ')'
{
Constraint *n = makeNode(Constraint);
n->contype = CONSTR_CHECK;
n->location = @1;
- n->raw_expr = $3;
+ n->is_no_inherit = $2;
+ n->raw_expr = $4;
n->cooked_expr = NULL;
$$ = (Node *)n;
}
@@ -2810,14 +2811,15 @@ TableConstraint:
;
ConstraintElem:
- CHECK '(' a_expr ')' ConstraintAttributeSpec
+ CHECK opt_no_inherit '(' a_expr ')' ConstraintAttributeSpec
{
Constraint *n = makeNode(Constraint);
n->contype = CONSTR_CHECK;
n->location = @1;
- n->raw_expr = $3;
+ n->is_no_inherit = $2;
+ n->raw_expr = $4;
n->cooked_expr = NULL;
- processCASbits($5, @5, "CHECK",
+ processCASbits($6, @6, "CHECK",
NULL, NULL, &n->skip_validation,
yyscanner);
n->initially_valid = !n->skip_validation;
@@ -2920,6 +2922,10 @@ ConstraintElem:
}
;
+opt_no_inherit: NO INHERIT { $$ = TRUE; }
+ | /* EMPTY */ { $$ = FALSE; }
+ ;
+
opt_column_list:
'(' columnList ')' { $$ = $2; }
| /*EMPTY*/ { $$ = NIL; }