@@ -101,6 +101,7 @@ typedef struct PrivTarget
101
101
#define CAS_INITIALLY_IMMEDIATE 0x04
102
102
#define CAS_INITIALLY_DEFERRED 0x08
103
103
#define CAS_NOT_VALID 0x10
104
+ #define CAS_NO_INHERIT 0x20
104
105
105
106
106
107
#define parser_yyerror (msg ) scanner_yyerror(msg, yyscanner)
@@ -144,7 +145,7 @@ static void SplitColQualList(List *qualList,
144
145
core_yyscan_t yyscanner);
145
146
static void processCASbits (int cas_bits,int location,const char *constrType,
146
147
bool *deferrable,bool *initdeferred,bool *not_valid,
147
- core_yyscan_t yyscanner);
148
+ bool *no_inherit, core_yyscan_t yyscanner);
148
149
149
150
%}
150
151
@@ -2709,13 +2710,13 @@ ColConstraintElem:
2709
2710
n->indexspace =$4 ;
2710
2711
$$ = (Node *)n;
2711
2712
}
2712
- | CHECK opt_no_inherit ' (' a_expr ' )'
2713
+ | CHECK ' (' a_expr ' )' opt_no_inherit
2713
2714
{
2714
2715
Constraint *n = makeNode(Constraint);
2715
2716
n->contype = CONSTR_CHECK;
2716
2717
n->location =@1 ;
2717
- n->is_no_inherit =$2 ;
2718
- n->raw_expr =$4 ;
2718
+ n->is_no_inherit =$5 ;
2719
+ n->raw_expr =$3 ;
2719
2720
n->cooked_expr =NULL ;
2720
2721
$$ = (Node *)n;
2721
2722
}
@@ -2755,10 +2756,10 @@ ColConstraintElem:
2755
2756
* combinations.
2756
2757
*
2757
2758
* See also ConstraintAttributeSpec, which can be used in places where
2758
- * there is no parsing conflict. (Note: currently, NOT VALIDis an allowed
2759
- *clause in ConstraintAttributeSpec, but not here. Someday we might need
2760
- * to allowit here too, but for the moment it doesn't seem useful in the
2761
- * statements that use ConstraintAttr.)
2759
+ * there is no parsing conflict. (Note: currently, NOT VALIDand NO INHERIT
2760
+ *are allowed clauses in ConstraintAttributeSpec, but not here. Someday we
2761
+ *might need to allowthem here too, but for the moment it doesn't seem
2762
+ *useful in the statements that use ConstraintAttr.)
2762
2763
*/
2763
2764
ConstraintAttr :
2764
2765
DEFERRABLE
@@ -2835,17 +2836,16 @@ TableConstraint:
2835
2836
;
2836
2837
2837
2838
ConstraintElem :
2838
- CHECK opt_no_inherit ' (' a_expr ' )' ConstraintAttributeSpec
2839
+ CHECK ' (' a_expr ' )' ConstraintAttributeSpec
2839
2840
{
2840
2841
Constraint *n = makeNode(Constraint);
2841
2842
n->contype = CONSTR_CHECK;
2842
2843
n->location =@1 ;
2843
- n->is_no_inherit =$2 ;
2844
- n->raw_expr =$4 ;
2844
+ n->raw_expr =$3 ;
2845
2845
n->cooked_expr =NULL ;
2846
- processCASbits ($6 , @6 ," CHECK" ,
2846
+ processCASbits ($5 , @5 ," CHECK" ,
2847
2847
NULL ,NULL , &n->skip_validation,
2848
- yyscanner);
2848
+ &n->is_no_inherit, yyscanner);
2849
2849
n->initially_valid = !n->skip_validation;
2850
2850
$$ = (Node *)n;
2851
2851
}
@@ -2861,7 +2861,7 @@ ConstraintElem:
2861
2861
n->indexspace =$6 ;
2862
2862
processCASbits ($7 , @7 ," UNIQUE" ,
2863
2863
&n->deferrable, &n->initdeferred,NULL ,
2864
- yyscanner);
2864
+ NULL , yyscanner);
2865
2865
$$ = (Node *)n;
2866
2866
}
2867
2867
| UNIQUE ExistingIndex ConstraintAttributeSpec
@@ -2875,7 +2875,7 @@ ConstraintElem:
2875
2875
n->indexspace =NULL ;
2876
2876
processCASbits ($3 , @3 ," UNIQUE" ,
2877
2877
&n->deferrable, &n->initdeferred,NULL ,
2878
- yyscanner);
2878
+ NULL , yyscanner);
2879
2879
$$ = (Node *)n;
2880
2880
}
2881
2881
| PRIMARY KEY ' (' columnList ' )' opt_definition OptConsTableSpace
@@ -2890,7 +2890,7 @@ ConstraintElem:
2890
2890
n->indexspace =$7 ;
2891
2891
processCASbits ($8 , @8 ," PRIMARY KEY" ,
2892
2892
&n->deferrable, &n->initdeferred,NULL ,
2893
- yyscanner);
2893
+ NULL , yyscanner);
2894
2894
$$ = (Node *)n;
2895
2895
}
2896
2896
| PRIMARY KEY ExistingIndex ConstraintAttributeSpec
@@ -2904,7 +2904,7 @@ ConstraintElem:
2904
2904
n->indexspace =NULL ;
2905
2905
processCASbits ($4 , @4 ," PRIMARY KEY" ,
2906
2906
&n->deferrable, &n->initdeferred,NULL ,
2907
- yyscanner);
2907
+ NULL , yyscanner);
2908
2908
$$ = (Node *)n;
2909
2909
}
2910
2910
| EXCLUDE access_method_clause ' (' ExclusionConstraintList ' )'
@@ -2922,7 +2922,7 @@ ConstraintElem:
2922
2922
n->where_clause=$8 ;
2923
2923
processCASbits ($9 , @9 ," EXCLUDE" ,
2924
2924
&n->deferrable, &n->initdeferred,NULL ,
2925
- yyscanner);
2925
+ NULL , yyscanner);
2926
2926
$$ = (Node *)n;
2927
2927
}
2928
2928
| FOREIGN KEY ' (' columnList ' )' REFERENCES qualified_name
@@ -2939,7 +2939,7 @@ ConstraintElem:
2939
2939
n->fk_del_action= (char ) ($10 &0xFF );
2940
2940
processCASbits ($11 , @11 ," FOREIGN KEY" ,
2941
2941
&n->deferrable, &n->initdeferred,
2942
- &n->skip_validation,
2942
+ &n->skip_validation,NULL ,
2943
2943
yyscanner);
2944
2944
n->initially_valid = !n->skip_validation;
2945
2945
$$ = (Node *)n;
@@ -4133,7 +4133,7 @@ CreateTrigStmt:
4133
4133
n->isconstraint =TRUE ;
4134
4134
processCASbits ($10 , @10 ," TRIGGER" ,
4135
4135
&n->deferrable, &n->initdeferred,NULL ,
4136
- yyscanner);
4136
+ NULL , yyscanner);
4137
4137
n->constrrel =$9 ;
4138
4138
$$ = (Node *)n;
4139
4139
}
@@ -4270,6 +4270,7 @@ ConstraintAttributeElem:
4270
4270
| INITIALLY IMMEDIATE {$$ = CAS_INITIALLY_IMMEDIATE; }
4271
4271
| INITIALLY DEFERRED {$$ = CAS_INITIALLY_DEFERRED; }
4272
4272
| NOT VALID {$$ = CAS_NOT_VALID; }
4273
+ | NO INHERIT {$$ = CAS_NO_INHERIT; }
4273
4274
;
4274
4275
4275
4276
@@ -4386,7 +4387,7 @@ CreateAssertStmt:
4386
4387
n->isconstraint =TRUE ;
4387
4388
processCASbits ($8 , @8 ," ASSERTION" ,
4388
4389
&n->deferrable, &n->initdeferred,NULL ,
4389
- yyscanner);
4390
+ NULL , yyscanner);
4390
4391
4391
4392
ereport (ERROR,
4392
4393
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
@@ -13380,7 +13381,7 @@ SplitColQualList(List *qualList,
13380
13381
static void
13381
13382
processCASbits(int cas_bits, int location, const char *constrType,
13382
13383
bool *deferrable, bool *initdeferred, bool *not_valid,
13383
- core_yyscan_t yyscanner)
13384
+ bool *no_inherit, core_yyscan_t yyscanner)
13384
13385
{
13385
13386
/* defaults*/
13386
13387
if (deferrable)
@@ -13428,6 +13429,19 @@ processCASbits(int cas_bits, int location, const char *constrType,
13428
13429
constrType),
13429
13430
parser_errposition(location)));
13430
13431
}
13432
+
13433
+ if (cas_bits & CAS_NO_INHERIT)
13434
+ {
13435
+ if (no_inherit)
13436
+ *no_inherit = true;
13437
+ else
13438
+ ereport(ERROR,
13439
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
13440
+ /* translator: %s is CHECK, UNIQUE, or similar*/
13441
+ errmsg("%s constraints cannot be marked NO INHERIT",
13442
+ constrType),
13443
+ parser_errposition(location)));
13444
+ }
13431
13445
}
13432
13446
13433
13447
/* parser_init()