这是我的做法:
CREATE EXTENSION IF NOT EXISTS postgres_fdw;
DROP SERVER IF EXISTS myserver CASCADE;
CREATE SERVER myserver FOREIGN DATA WRAPPER postgres_fdw OPTIONS (host '10.1.1.1', dbname 'mydb', port '5432');
DROP USER MAPPING IF EXISTS FOR user SERVER myserver;
CREATE USER MAPPING FOR user
SERVER myserver
OPTIONS (user 'user', password 'password');
CREATE FOREIGN TABLE IF NOT EXISTS foriegnemployee(
id int,
name text,
is_done boolean
)
SERVER myserver
OPTIONS (schema_name 'myschema', table_name 'employee');
当我运行以下查询时,它说表 mydb.employee 不存在:
Update foriegnemployee set is_done=true where id in (select id from sometable);
sometable 是一个本地表。员工表在远程数据库中