mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
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
This commit is contained in:
@ -111,6 +111,13 @@ typedef struct PrivTarget
|
||||
List *objs;
|
||||
} PrivTarget;
|
||||
|
||||
/* Private struct for the result of import_qualification production */
|
||||
typedef struct ImportQual
|
||||
{
|
||||
ImportForeignSchemaType type;
|
||||
List *table_names;
|
||||
} ImportQual;
|
||||
|
||||
/* ConstraintAttributeSpec yields an integer bitmask of these flags: */
|
||||
#define CAS_NOT_DEFERRABLE 0x01
|
||||
#define CAS_DEFERRABLE 0x02
|
||||
@ -212,6 +219,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
|
||||
ResTarget *target;
|
||||
struct PrivTarget *privtarget;
|
||||
AccessPriv *accesspriv;
|
||||
struct ImportQual *importqual;
|
||||
InsertStmt *istmt;
|
||||
VariableSetStmt *vsetstmt;
|
||||
}
|
||||
@ -238,8 +246,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
|
||||
DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
|
||||
DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
|
||||
DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
|
||||
GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
|
||||
LockStmt NotifyStmt ExplainableStmt PreparableStmt
|
||||
GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
|
||||
ListenStmt LoadStmt LockStmt NotifyStmt ExplainableStmt PreparableStmt
|
||||
CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
|
||||
RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
|
||||
RuleActionStmt RuleActionStmtOrEmpty RuleStmt
|
||||
@ -322,6 +330,8 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
|
||||
%type <ival> defacl_privilege_target
|
||||
%type <defelt> DefACLOption
|
||||
%type <list> DefACLOptionList
|
||||
%type <ival> import_qualification_type
|
||||
%type <importqual> import_qualification
|
||||
|
||||
%type <list> stmtblock stmtmulti
|
||||
OptTableElementList TableElementList OptInherit definition
|
||||
@ -556,7 +566,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
|
||||
|
||||
HANDLER HAVING HEADER_P HOLD HOUR_P
|
||||
|
||||
IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
|
||||
IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P
|
||||
INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
|
||||
INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
|
||||
INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
|
||||
@ -802,6 +812,7 @@ stmt :
|
||||
| FetchStmt
|
||||
| GrantStmt
|
||||
| GrantRoleStmt
|
||||
| ImportForeignSchemaStmt
|
||||
| IndexStmt
|
||||
| InsertStmt
|
||||
| ListenStmt
|
||||
@ -4272,6 +4283,52 @@ AlterForeignTableStmt:
|
||||
}
|
||||
;
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* QUERY:
|
||||
* IMPORT FOREIGN SCHEMA remote_schema
|
||||
* [ { LIMIT TO | EXCEPT } ( table_list ) ]
|
||||
* FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ImportForeignSchemaStmt:
|
||||
IMPORT_P FOREIGN SCHEMA name import_qualification
|
||||
FROM SERVER name INTO name create_generic_options
|
||||
{
|
||||
ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
|
||||
n->server_name = $8;
|
||||
n->remote_schema = $4;
|
||||
n->local_schema = $10;
|
||||
n->list_type = $5->type;
|
||||
n->table_list = $5->table_names;
|
||||
n->options = $11;
|
||||
$$ = (Node *) n;
|
||||
}
|
||||
;
|
||||
|
||||
import_qualification_type:
|
||||
LIMIT TO { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
|
||||
| EXCEPT { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
|
||||
;
|
||||
|
||||
import_qualification:
|
||||
import_qualification_type '(' relation_expr_list ')'
|
||||
{
|
||||
ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
|
||||
n->type = $1;
|
||||
n->table_names = $3;
|
||||
$$ = n;
|
||||
}
|
||||
| /*EMPTY*/
|
||||
{
|
||||
ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
|
||||
n->type = FDW_IMPORT_SCHEMA_ALL;
|
||||
n->table_names = NIL;
|
||||
$$ = n;
|
||||
}
|
||||
;
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* QUERY:
|
||||
@ -12909,6 +12966,7 @@ unreserved_keyword:
|
||||
| IMMEDIATE
|
||||
| IMMUTABLE
|
||||
| IMPLICIT_P
|
||||
| IMPORT_P
|
||||
| INCLUDING
|
||||
| INCREMENT
|
||||
| INDEX
|
||||
|
Reference in New Issue
Block a user