0

这是我的做法:

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 是一个本地表。员工表在远程数据库中

4

1 回答 1

1

我试图模拟你的桌子:

t=# create database b;
CREATE DATABASE
t=# \c b
You are now connected to database "b" as user "vao".
b=#  create table employee (is_done boolean, user_id int);
CREATE TABLE
b=# insert into employee select false,1;
INSERT 0 1
b=# \c t
You are now connected to database "t" as user "vao".
t=# create extension postgres_fdw;
CREATE EXTENSION
t=# create server b foreign data wrapper postgres_fdw options (dbname 'b');
CREATE SERVER
t=# create user mapping for vao server b;
CREATE USER MAPPING
t=# create foreign table ftb (is_done boolean, user_id int) server b options (table_name 'employee');
CREATE FOREIGN TABLE
t=# Update ftb set is_done=true where user_id in (select user_id from employee);
UPDATE 1

代码有效。我想服务器或表都有错误的选项

于 2016-11-18T11:51:22.773 回答