diff options
Diffstat (limited to 'src/backend/utils/adt/misc.c')
-rw-r--r-- | src/backend/utils/adt/misc.c | 31 |
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)); +} |