Skip to main content

PostgreSQL FDW

mysql_fdw#

CREATE EXTENSION mysql_fdw;
CREATE SERVER mysql_serverFOREIGN DATA WRAPPER mysql_fdwOPTIONS (host '127.0.0.1', port '3306');
CREATE USER MAPPING FOR postgresSERVER mysql_serverOPTIONS (username 'foo', password 'bar');
CREATE FOREIGN TABLE warehouse(     warehouse_id int,     warehouse_name text,     warehouse_created datetime)SERVER mysql_server     OPTIONS (dbname 'db', table_name 'warehouse');

postgres_fdw#

caution
CREATE EXTENSION postgres_fdw;
CREATE SERVER ext_serverFOREIGN DATA WRAPPER postgres_fdwOPTIONS (host '127.0.0.1', port '5432', dbname 'ext');
CREATE USER MAPPING FOR demoSERVER ext_serverOPTIONS (user 'ext', password 'ext');
CREATE FOREIGN TABLE foreign_table (        id integer NOT NULL,        data text)SERVER foreign_serverOPTIONS (schema_name 'some_schema', table_name 'some_table');

dblink#

CREATE EXTENSION dblink;
SELECT dblink_connect('myconn', 'db2remote');
CREATE SERVER db2remoteFOREIGN DATA WRAPPER dblink_fdwOPTIONS (host 'postgres.demoproject.aivencloud.com', dbname 'db2', port '11254');SELECT * FROM dblink('myconn','SELECT * FROM foo') AS t(a int);

sqlite_fdw#

CREATE EXTENSION sqlite_fdw;
CREATE SERVER sqlite_server FOREIGN DATA WRAPPER sqlite_fdw OPTIONS (database '/tmp/test.db');CREATE FOREIGN TABLE t1(a integer, b text) SERVER sqlite_server OPTIONS (table 't1_sqlite');-- 需要 key 支持更新CREATE FOREIGN TABLE t1(a integer OPTIONS (key 'true'), b text) SERVER sqlite_server OPTIONS (table 't1_sqlite');-- int 转 timestampCREATE FOREIGN TABLE t1(a integer, b text, c timestamp without time zone OPTIONS (column_type 'INT')) SERVER sqlite_server OPTIONS (table 't1_sqlite');
IMPORT FOREIGN SCHEMA public FROM SERVER sqlite_server INTO public;