aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/postgres_fdw.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-03-31 15:01:35 -0400
committerRobert Haas <rhaas@postgresql.org>2017-03-31 15:06:34 -0400
commitf49bcd4ef3e9a75de210357a4d9bbe3e004db956 (patch)
tree1dac9f1a102983c182154bf240732a88df139a70 /contrib/postgres_fdw/postgres_fdw.c
parente306df7f9cd6b4433273e006df11bdc966b7079e (diff)
downloadpostgresql-f49bcd4ef3e9a75de210357a4d9bbe3e004db956.tar.gz
postgresql-f49bcd4ef3e9a75de210357a4d9bbe3e004db956.zip
postgres_fdw: Teach IMPORT FOREIGN SCHEMA about partitioning.
Don't import partitions. Do import partitioned tables which are not themselves partitions. Report by Stephen Frost. Design and patch by Michael Paquier, reviewed by Amit Langote. Documentation revised by me. Discussion: http://postgr.es/m/20170309141531.GD9812@tamriel.snowman.net
Diffstat (limited to 'contrib/postgres_fdw/postgres_fdw.c')
-rw-r--r--contrib/postgres_fdw/postgres_fdw.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c
index 03f14800b0e..54b938734a8 100644
--- a/contrib/postgres_fdw/postgres_fdw.c
+++ b/contrib/postgres_fdw/postgres_fdw.c
@@ -3849,6 +3849,10 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
* should save a few cycles to not process excluded tables in the
* first place.)
*
+ * Ignore table data for partitions and only include the definitions
+ * of the root partitioned tables to allow access to the complete
+ * remote data set locally in the schema imported.
+ *
* Note: because we run the connection with search_path restricted to
* pg_catalog, the format_type() and pg_get_expr() outputs will always
* include a schema name for types/functions in other schemas, which
@@ -3897,10 +3901,15 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
CppAsString2(RELKIND_RELATION) ","
CppAsString2(RELKIND_VIEW) ","
CppAsString2(RELKIND_FOREIGN_TABLE) ","
- CppAsString2(RELKIND_MATVIEW) ") "
+ CppAsString2(RELKIND_MATVIEW) ","
+ CppAsString2(RELKIND_PARTITIONED_TABLE) ") "
" AND n.nspname = ");
deparseStringLiteral(&buf, stmt->remote_schema);
+ /* Partitions are supported since Postgres 10 */
+ if (PQserverVersion(conn) >= 100000)
+ appendStringInfoString(&buf, " AND NOT c.relispartition ");
+
/* Apply restrictions for LIMIT TO and EXCEPT */
if (stmt->list_type == FDW_IMPORT_SCHEMA_LIMIT_TO ||
stmt->list_type == FDW_IMPORT_SCHEMA_EXCEPT)