diff options
author | Stephen Frost <sfrost@snowman.net> | 2013-07-18 17:10:16 -0400 |
---|---|---|
committer | Stephen Frost <sfrost@snowman.net> | 2013-07-18 17:10:16 -0400 |
commit | 4cbe3ac3e86790d05c569de4585e5075a62a9b41 (patch) | |
tree | 8adc929520d4103b4493c0c23bcb7d2b2c2a5a4d /src/backend/commands/tablecmds.c | |
parent | 6f9e39bc9993c18686f0950f9b9657c7c97c7450 (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/commands/tablecmds.c')
-rw-r--r-- | src/backend/commands/tablecmds.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index bd0a21987c8..cb87d906ef8 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8774,6 +8774,42 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation, break; } + /* Special-case validation of view options */ + if (rel->rd_rel->relkind == RELKIND_VIEW) + { + Query *view_query = get_view_query(rel); + List *view_options = untransformRelOptions(newOptions); + ListCell *cell; + bool check_option = false; + bool security_barrier = false; + + foreach(cell, view_options) + { + DefElem *defel = (DefElem *) lfirst(cell); + + if (pg_strcasecmp(defel->defname, "check_option") == 0) + check_option = true; + if (pg_strcasecmp(defel->defname, "security_barrier") == 0) + security_barrier = defGetBoolean(defel); + } + + /* + * If the check option is specified, look to see if the view is + * actually auto-updatable or not. + */ + if (check_option) + { + const char *view_updatable_error = + view_query_is_auto_updatable(view_query, security_barrier); + + if (view_updatable_error) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("WITH CHECK OPTION is supported only on auto-updatable views"), + errhint("%s", view_updatable_error))); + } + } + /* * All we need do here is update the pg_class row; the new options will be * propagated into relcaches during post-commit cache inval. |