简体   繁体   English

Postgres fdw 使用外部触发器插入记录

[英]Postgres fdw inserting record with foreign triggers

I have established a foreign data wrapper to a second Postgres database and imported the foreign schema.我已经为第二个 Postgres 数据库建立了一个外部数据包装器并导入了外部模式。 Now, when I attempt to insert a row to one of the foreign tables from my primary database it hits a function called on the insert trigger.现在,当我尝试从我的主数据库向其中一个外部表插入一行时,它会在插入触发器上调用 function。 This trigger is checking another table that exists on the foreign table but it says the "relation "the_other_table" does not exist. I can select from it from the primary database but while executing the trigger it cannot see it.此触发器正在检查外部表上存在的另一个表,但它说“关系“the_other_table”不存在。我可以从主数据库中从中获取 select,但在执行触发器时它看不到它。

I tried with the two schemas being the same name then reimported the schema to a different name and still nothing.我尝试使用相同名称的两个模式,然后将模式重新导入到不同的名称,但仍然没有。 It is as though it is executing the trigger on my primary but not knowing where to look for the other table.就好像它正在我的主表上执行触发器,但不知道在哪里寻找另一个表。

Any ideas?有任何想法吗?

I don't see this problem in general, so it must be something specifically about your set up.我一般看不到这个问题,所以它一定是关于你的设置的。

cat fdw_trigger.sql:猫 fdw_trigger.sql:

create database fgn;
\c fgn
create table a (x int);
create table b (x int);
create or replace function foobar() returns trigger language plpgsql as $$ BEGIN insert into public.b values(NEW.x); return new; END $$;
create trigger lsadkjf before insert on a for each row execute function foobar() ;
\c postgres
create schema fgn;
create extension postgres_fdw ;
create server fgn foreign data wrapper postgres_fdw OPTIONS ( dbname 'fgn');
create user MAPPING FOR CURRENT_USER SERVER fgn;
import foreign schema public from server fgn into fgn;
insert into fgn.a  values (13);
\c fgn
select * from b ;
select * from a ;

psql postgres -f fdw_trigger.sql psql postgres -f fdw_trigger.sql

works as expected.按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM