From dc3eb5638349e74a6628130a5101ce866455f4a3 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 12 Jun 2013 17:52:54 -0400 Subject: Improve updatability checking for views and foreign tables. Extend the FDW API (which we already changed for 9.3) so that an FDW can report whether specific foreign tables are insertable/updatable/deletable. The default assumption continues to be that they're updatable if the relevant executor callback function is supplied by the FDW, but finer granularity is now possible. As a test case, add an "updatable" option to contrib/postgres_fdw. This patch also fixes the information_schema views, which previously did not think that foreign tables were ever updatable, and fixes view_is_auto_updatable() so that a view on a foreign table can be auto-updatable. initdb forced due to changes in information_schema views and the functions they rely on. This is a bit unfortunate to do post-beta1, but if we don't change this now then we'll have another API break for FDWs when we do change it. Dean Rasheed, somewhat editorialized on by Tom Lane --- doc/src/sgml/fdwhandler.sgml | 27 +++++++++++++++++++++++++++ doc/src/sgml/postgres-fdw.sgml | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) (limited to 'doc/src') diff --git a/doc/src/sgml/fdwhandler.sgml b/doc/src/sgml/fdwhandler.sgml index 912ca8663ef..6c06f1a4367 100644 --- a/doc/src/sgml/fdwhandler.sgml +++ b/doc/src/sgml/fdwhandler.sgml @@ -565,6 +565,33 @@ EndForeignModify (EState *estate, NULL, no action is taken during executor shutdown. + + +int +IsForeignRelUpdatable (Relation rel); + + + Report which update operations the specified foreign table supports. + The return value should be a bitmask of rule event numbers indicating + which operations are supported by the foreign table, using the + CmdType enumeration; that is, + (1 << CMD_UPDATE) = 4 for UPDATE, + (1 << CMD_INSERT) = 8 for INSERT, and + (1 << CMD_DELETE) = 16 for DELETE. + + + + If the IsForeignRelUpdatable pointer is set to + NULL, foreign tables are assumed to be insertable, updatable, + or deletable if the FDW provides ExecForeignInsert, + ExecForeignUpdate, or ExecForeignDelete + respectively. This function is only needed if the FDW supports some + tables that are updatable and some that are not. (Even then, it's + permissible to throw an error in the execution routine instead of + checking in this function. However, this function is used to determine + updatability for display in the information_schema views.) + + diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml index a1c3bebb097..35924f19f26 100644 --- a/doc/src/sgml/postgres-fdw.sgml +++ b/doc/src/sgml/postgres-fdw.sgml @@ -254,6 +254,43 @@ + + + Updatability Options + + + By default all foreign tables using postgres_fdw are assumed + to be updatable. This may be overridden using the following option: + + + + + + updatable + + + This option controls whether postgres_fdw allows foreign + tables to be modified using INSERT, UPDATE and + DELETE commands. It can be specified for a foreign table + or a foreign server. A table-level option overrides a server-level + option. + The default is true. + + + + Of course, if the remote table is not in fact updatable, an error + would occur anyway. Use of this option primarily allows the error to + be thrown locally without querying the remote server. Note however + that the information_schema views will report a + postgres_fdw foreign table to be updatable (or not) + according to the setting of this option, without any check of the + remote server. + + + + + + -- cgit v1.2.3