From a99c42f291421572aef2b0a9360294c7d89b8bc7 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 8 Dec 2012 18:25:48 -0500 Subject: Support automatically-updatable views. This patch makes "simple" views automatically updatable, without the need to create either INSTEAD OF triggers or INSTEAD rules. "Simple" views are those classified as updatable according to SQL-92 rules. The rewriter transforms INSERT/UPDATE/DELETE commands on such views directly into an equivalent command on the underlying table, which will generally have noticeably better performance than is possible with either triggers or user-written rules. A view that has INSTEAD OF triggers or INSTEAD rules continues to operate the same as before. For the moment, security_barrier views are not considered simple. Also, we do not support WITH CHECK OPTION. These features may be added in future. Dean Rasheed, reviewed by Amit Kapila --- src/backend/utils/adt/misc.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/backend/utils/adt/misc.c') diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index cd20b838416..407946715e2 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -28,6 +28,7 @@ #include "miscadmin.h" #include "parser/keywords.h" #include "postmaster/syslogger.h" +#include "rewrite/rewriteHandler.h" #include "storage/fd.h" #include "storage/pmsignal.h" #include "storage/proc.h" @@ -523,3 +524,33 @@ pg_collation_for(PG_FUNCTION_ARGS) PG_RETURN_NULL(); PG_RETURN_TEXT_P(cstring_to_text(generate_collation_name(collid))); } + + +/* + * information_schema support functions + * + * Test whether a view (identified by pg_class OID) is insertable-into or + * updatable. The latter requires delete capability too. This is an + * artifact of the way the SQL standard defines the information_schema views: + * if we defined separate functions for update and delete, we'd double the + * work required to compute the view columns. + * + * These rely on relation_is_updatable(), which is in rewriteHandler.c. + */ +Datum +pg_view_is_insertable(PG_FUNCTION_ARGS) +{ + Oid viewoid = PG_GETARG_OID(0); + int req_events = (1 << CMD_INSERT); + + PG_RETURN_BOOL(relation_is_updatable(viewoid, req_events)); +} + +Datum +pg_view_is_updatable(PG_FUNCTION_ARGS) +{ + Oid viewoid = PG_GETARG_OID(0); + int req_events = (1 << CMD_UPDATE) | (1 << CMD_DELETE); + + PG_RETURN_BOOL(relation_is_updatable(viewoid, req_events)); +} -- cgit v1.2.3