What am I doing here while updating a table in a remote db using postgres_fdw?

流过昼夜 提交于 2019-12-25 04:04:17

问题


Here is how I am doing it:

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');

When I run the following query, it says table mydb.employee does not not exist:

Update foriegnemployee set is_done=true where id in (select id from sometable);

sometable is a local table. employee table is in a remote db


回答1:


I tried to mockup your tables:

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

code works. Either server or table have wrong options I suppose



来源:https://stackoverflow.com/questions/40675766/what-am-i-doing-here-while-updating-a-table-in-a-remote-db-using-postgres-fdw

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!