CREATE TABLE import_source."x 4" (c1 float8, "C 2" text, c3 varchar(42));
CREATE TABLE import_source."x 5" (c1 float8);
ALTER TABLE import_source."x 5" DROP COLUMN c1;
+CREATE TABLE import_source.t4 (c1 int) PARTITION BY RANGE (c1);
+CREATE TABLE import_source.t4_part PARTITION OF import_source.t4
+ FOR VALUES FROM (1) TO (100);
CREATE SCHEMA import_dest1;
IMPORT FOREIGN SCHEMA import_source FROM SERVER loopback INTO import_dest1;
\det+ import_dest1.*
import_dest1 | t1 | loopback | (schema_name 'import_source', table_name 't1') |
import_dest1 | t2 | loopback | (schema_name 'import_source', table_name 't2') |
import_dest1 | t3 | loopback | (schema_name 'import_source', table_name 't3') |
+ import_dest1 | t4 | loopback | (schema_name 'import_source', table_name 't4') |
import_dest1 | x 4 | loopback | (schema_name 'import_source', table_name 'x 4') |
import_dest1 | x 5 | loopback | (schema_name 'import_source', table_name 'x 5') |
-(5 rows)
+(6 rows)
\d import_dest1.*
Foreign table "import_dest1.t1"
Server: loopback
FDW Options: (schema_name 'import_source', table_name 't3')
+ Foreign table "import_dest1.t4"
+ Column | Type | Collation | Nullable | Default | FDW Options
+--------+---------+-----------+----------+---------+--------------------
+ c1 | integer | | not null | | (column_name 'c1')
+Server: loopback
+FDW Options: (schema_name 'import_source', table_name 't4')
+
Foreign table "import_dest1.x 4"
Column | Type | Collation | Nullable | Default | FDW Options
--------+-----------------------+-----------+----------+---------+---------------------
import_dest2 | t1 | loopback | (schema_name 'import_source', table_name 't1') |
import_dest2 | t2 | loopback | (schema_name 'import_source', table_name 't2') |
import_dest2 | t3 | loopback | (schema_name 'import_source', table_name 't3') |
+ import_dest2 | t4 | loopback | (schema_name 'import_source', table_name 't4') |
import_dest2 | x 4 | loopback | (schema_name 'import_source', table_name 'x 4') |
import_dest2 | x 5 | loopback | (schema_name 'import_source', table_name 'x 5') |
-(5 rows)
+(6 rows)
\d import_dest2.*
Foreign table "import_dest2.t1"
Server: loopback
FDW Options: (schema_name 'import_source', table_name 't3')
+ Foreign table "import_dest2.t4"
+ Column | Type | Collation | Nullable | Default | FDW Options
+--------+---------+-----------+----------+---------+--------------------
+ c1 | integer | | not null | | (column_name 'c1')
+Server: loopback
+FDW Options: (schema_name 'import_source', table_name 't4')
+
Foreign table "import_dest2.x 4"
Column | Type | Collation | Nullable | Default | FDW Options
--------+-----------------------+-----------+----------+---------+---------------------
import_dest3 | t1 | loopback | (schema_name 'import_source', table_name 't1') |
import_dest3 | t2 | loopback | (schema_name 'import_source', table_name 't2') |
import_dest3 | t3 | loopback | (schema_name 'import_source', table_name 't3') |
+ import_dest3 | t4 | loopback | (schema_name 'import_source', table_name 't4') |
import_dest3 | x 4 | loopback | (schema_name 'import_source', table_name 'x 4') |
import_dest3 | x 5 | loopback | (schema_name 'import_source', table_name 'x 5') |
-(5 rows)
+(6 rows)
\d import_dest3.*
Foreign table "import_dest3.t1"
Server: loopback
FDW Options: (schema_name 'import_source', table_name 't3')
+ Foreign table "import_dest3.t4"
+ Column | Type | Collation | Nullable | Default | FDW Options
+--------+---------+-----------+----------+---------+--------------------
+ c1 | integer | | | | (column_name 'c1')
+Server: loopback
+FDW Options: (schema_name 'import_source', table_name 't4')
+
Foreign table "import_dest3.x 4"
Column | Type | Collation | Nullable | Default | FDW Options
--------+-----------------------+-----------+----------+---------+---------------------
import_dest4 | t1 | loopback | (schema_name 'import_source', table_name 't1') |
import_dest4 | t2 | loopback | (schema_name 'import_source', table_name 't2') |
import_dest4 | t3 | loopback | (schema_name 'import_source', table_name 't3') |
+ import_dest4 | t4 | loopback | (schema_name 'import_source', table_name 't4') |
import_dest4 | x 5 | loopback | (schema_name 'import_source', table_name 'x 5') |
-(4 rows)
+(5 rows)
-- Assorted error cases
IMPORT FOREIGN SCHEMA import_source FROM SERVER loopback INTO import_dest4;
* 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
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)