summaryrefslogtreecommitdiff
path: root/src/backend/parser
diff options
context:
space:
mode:
authorStephen Frost2013-07-18 21:10:16 +0000
committerStephen Frost2013-07-18 21:10:16 +0000
commit4cbe3ac3e86790d05c569de4585e5075a62a9b41 (patch)
tree8adc929520d4103b4493c0c23bcb7d2b2c2a5a4d /src/backend/parser
parent6f9e39bc9993c18686f0950f9b9657c7c97c7450 (diff)
WITH CHECK OPTION support for auto-updatable VIEWs
For simple views which are automatically updatable, this patch allows the user to specify what level of checking should be done on records being inserted or updated. For 'LOCAL CHECK', new tuples are validated against the conditionals of the view they are being inserted into, while for 'CASCADED CHECK' the new tuples are validated against the conditionals for all views involved (from the top down). This option is part of the SQL specification. Dean Rasheed, reviewed by Pavel Stehule
Diffstat (limited to 'src/backend/parser')
-rw-r--r--src/backend/parser/gram.y43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 57f49d6d517..d8d2bdf09a4 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -470,7 +470,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
%type <list> constraints_set_list
%type <boolean> constraints_set_mode
%type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
-%type <list> opt_check_option
+%type <ival> opt_check_option
%type <str> opt_provider security_label
@@ -7995,6 +7995,7 @@ ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
n->query = $8;
n->replace = false;
n->options = $6;
+ n->withCheckOption = $9;
$$ = (Node *) n;
}
| CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
@@ -8007,10 +8008,11 @@ ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
n->query = $10;
n->replace = true;
n->options = $8;
+ n->withCheckOption = $11;
$$ = (Node *) n;
}
| CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
- AS SelectStmt
+ AS SelectStmt opt_check_option
{
ViewStmt *n = makeNode(ViewStmt);
n->view = $5;
@@ -8019,10 +8021,16 @@ ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
n->replace = false;
n->options = $9;
+ n->withCheckOption = $12;
+ if (n->withCheckOption != NO_CHECK_OPTION)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("WITH CHECK OPTION not supported on recursive views"),
+ parser_errposition(@12)));
$$ = (Node *) n;
}
| CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
- AS SelectStmt
+ AS SelectStmt opt_check_option
{
ViewStmt *n = makeNode(ViewStmt);
n->view = $7;
@@ -8031,30 +8039,21 @@ ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
n->replace = true;
n->options = $11;
+ n->withCheckOption = $14;
+ if (n->withCheckOption != NO_CHECK_OPTION)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("WITH CHECK OPTION not supported on recursive views"),
+ parser_errposition(@14)));
$$ = (Node *) n;
}
;
opt_check_option:
- WITH CHECK OPTION
- {
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("WITH CHECK OPTION is not implemented")));
- }
- | WITH CASCADED CHECK OPTION
- {
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("WITH CHECK OPTION is not implemented")));
- }
- | WITH LOCAL CHECK OPTION
- {
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("WITH CHECK OPTION is not implemented")));
- }
- | /* EMPTY */ { $$ = NIL; }
+ WITH CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
+ | WITH CASCADED CHECK OPTION { $$ = CASCADED_CHECK_OPTION; }
+ | WITH LOCAL CHECK OPTION { $$ = LOCAL_CHECK_OPTION; }
+ | /* EMPTY */ { $$ = NO_CHECK_OPTION; }
;
/*****************************************************************************