diff options
author | Robert Haas <rhaas@postgresql.org> | 2013-10-18 10:35:36 -0400 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2013-10-18 10:35:36 -0400 |
commit | cab5dc5daf2f6f5da0ce79deb399633b4bb443b5 (patch) | |
tree | 03a7cd95ec18a79cbd4d44862df1c9a914da728b /src/backend/utils/adt/misc.c | |
parent | 523beaa11bdf6a9864e8978b467ed586b792c9ca (diff) | |
download | postgresql-cab5dc5daf2f6f5da0ce79deb399633b4bb443b5.tar.gz postgresql-cab5dc5daf2f6f5da0ce79deb399633b4bb443b5.zip |
Allow only some columns of a view to be auto-updateable.
Previously, unless all columns were auto-updateable, we wouldn't
inserts, updates, or deletes, or at least not without a rule or trigger;
now, we'll allow inserts and updates that target only the auto-updateable
columns, and deletes even if there are no auto-updateable columns at
all provided the view definition is otherwise suitable.
Dean Rasheed, reviewed by Marko Tiikkaja
Diffstat (limited to 'src/backend/utils/adt/misc.c')
-rw-r--r-- | src/backend/utils/adt/misc.c | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 63a991631de..8b60253733b 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -20,6 +20,7 @@ #include <math.h> #include <unistd.h> +#include "access/sysattr.h" #include "catalog/catalog.h" #include "catalog/pg_tablespace.h" #include "catalog/pg_type.h" @@ -540,17 +541,13 @@ pg_relation_is_updatable(PG_FUNCTION_ARGS) Oid reloid = PG_GETARG_OID(0); bool include_triggers = PG_GETARG_BOOL(1); - PG_RETURN_INT32(relation_is_updatable(reloid, include_triggers)); + PG_RETURN_INT32(relation_is_updatable(reloid, include_triggers, NULL)); } /* * pg_column_is_updatable - determine whether a column is updatable * - * Currently we just check whether the column's relation is updatable. - * Eventually we might allow views to have some updatable and some - * non-updatable columns. - * - * Also, this function encapsulates the decision about just what + * This function encapsulates the decision about just what * information_schema.columns.is_updatable actually means. It's not clear * whether deletability of the column's relation should be required, so * we want that decision in C code where we could change it without initdb. @@ -560,6 +557,7 @@ pg_column_is_updatable(PG_FUNCTION_ARGS) { Oid reloid = PG_GETARG_OID(0); AttrNumber attnum = PG_GETARG_INT16(1); + AttrNumber col = attnum - FirstLowInvalidHeapAttributeNumber; bool include_triggers = PG_GETARG_BOOL(2); int events; @@ -567,7 +565,8 @@ pg_column_is_updatable(PG_FUNCTION_ARGS) if (attnum <= 0) PG_RETURN_BOOL(false); - events = relation_is_updatable(reloid, include_triggers); + events = relation_is_updatable(reloid, include_triggers, + bms_make_singleton(col)); /* We require both updatability and deletability of the relation */ #define REQ_EVENTS ((1 << CMD_UPDATE) | (1 << CMD_DELETE)) |