diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2014-07-10 15:01:31 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2014-07-10 15:01:43 -0400 |
commit | 59efda3e50ca4de6a9d5aa4491464e22b6329b1e (patch) | |
tree | 23a2fe16ebc11ad9f95ef3f70c563084d6ca4007 /src/backend/foreign/foreign.c | |
parent | 6a605cd6bd9f689b35676623add0de9b90978bf1 (diff) | |
download | postgresql-59efda3e50ca4de6a9d5aa4491464e22b6329b1e.tar.gz postgresql-59efda3e50ca4de6a9d5aa4491464e22b6329b1e.zip |
Implement IMPORT FOREIGN SCHEMA.
This command provides an automated way to create foreign table definitions
that match remote tables, thereby reducing tedium and chances for error.
In this patch, we provide the necessary core-server infrastructure and
implement the feature fully in the postgres_fdw foreign-data wrapper.
Other wrappers will throw a "feature not supported" error until/unless
they are updated.
Ronan Dunklau and Michael Paquier, additional work by me
Diffstat (limited to 'src/backend/foreign/foreign.c')
-rw-r--r-- | src/backend/foreign/foreign.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/backend/foreign/foreign.c b/src/backend/foreign/foreign.c index 6d548b7d08b..4f5f6ae362b 100644 --- a/src/backend/foreign/foreign.c +++ b/src/backend/foreign/foreign.c @@ -400,6 +400,47 @@ GetFdwRoutineForRelation(Relation relation, bool makecopy) /* + * IsImportableForeignTable - filter table names for IMPORT FOREIGN SCHEMA + * + * Returns TRUE if given table name should be imported according to the + * statement's import filter options. + */ +bool +IsImportableForeignTable(const char *tablename, + ImportForeignSchemaStmt *stmt) +{ + ListCell *lc; + + switch (stmt->list_type) + { + case FDW_IMPORT_SCHEMA_ALL: + return true; + + case FDW_IMPORT_SCHEMA_LIMIT_TO: + foreach(lc, stmt->table_list) + { + RangeVar *rv = (RangeVar *) lfirst(lc); + + if (strcmp(tablename, rv->relname) == 0) + return true; + } + return false; + + case FDW_IMPORT_SCHEMA_EXCEPT: + foreach(lc, stmt->table_list) + { + RangeVar *rv = (RangeVar *) lfirst(lc); + + if (strcmp(tablename, rv->relname) == 0) + return false; + } + return true; + } + return false; /* shouldn't get here */ +} + + +/* * deflist_to_tuplestore - Helper function to convert DefElem list to * tuplestore usable in SRF. */ |