aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/misc.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-12-08 18:25:48 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2012-12-08 18:26:21 -0500
commita99c42f291421572aef2b0a9360294c7d89b8bc7 (patch)
tree330ccf97fb7318f988d8218bb1a854bc84025d63 /src/backend/utils/adt/misc.c
parentd12d9f595e1c6bc6e62b7b423762fc03ad923899 (diff)
downloadpostgresql-a99c42f291421572aef2b0a9360294c7d89b8bc7.tar.gz
postgresql-a99c42f291421572aef2b0a9360294c7d89b8bc7.zip
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
Diffstat (limited to 'src/backend/utils/adt/misc.c')
-rw-r--r--src/backend/utils/adt/misc.c31
1 files changed, 31 insertions, 0 deletions
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));
+}