我有两个数据库,test1和test2
在test1中我有一个名为:emplyee的表 在test2中我有一个名为:user _ 的表我想要从表用户_
中不存在的表员工中提取用户我尝试使用此查询
select * from employee where mail_employe not in
( select emailaddress from test2.user_ )
我有这个错误:
ERROR: schema "test2" does not exist
LINE 3: ( select emailaddress from test2.user_ )
我也尝试使用这种语法:
select * from employee where mail_employe not in
(SELECT emailaddress from dblink('dbname=test2','SELECT emailaddress FROM user_'))
我也有这个错误
ERROR: a column definition list is required for functions returning "record"
LINE 3: (SELECT emailaddress from dblink('dbname=test2','SELEC...
已更新
我尝试使用SCHEMA的systax
在两个数据库中我有这个SCHEMA代码
CREATE SCHEMA public
AUTHORIZATION postgres;
GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO public;
COMMENT ON SCHEMA public
IS 'standard public schema';
我尝试使用此代码但没有成功
select * from test1.public.employee where mail_employe not in
(SELECT emailaddress from test2.public.user_')
但我有同样的错误
答案 0 :(得分:0)
示例:
CREATE SCHEMA sch1;
CREATE SCHEMA sch2;
CREATE TABLE sch1.foo ( id serial, name varchar );
CREATE TABLE sch2.bar ( id serial, title varchar );
查询:
SELECT sch1.foo.name, sch2.bar.title
FROM sch1.foo
INNER JOIN sch2.bar on sch1.foo.name = sch2.bar.title;
SELECT sch1.foo.name
FROM sch1.foo
WHERE sch1.foo.id IN (SELECT sch2.bar.id FROM sch2.bar);
不幸的是,只要您不改变搜索路径,就需要编写资源的完整路径。