mirror of
https://github.com/postgres/postgres.git
synced 2025-07-15 19:21:59 +03:00
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
This commit is contained in:
@ -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; }
|
||||
;
|
||||
|
||||
/*****************************************************************************
|
||||
|
Reference in New Issue
Block a user