SQL跨数据库查询

  1. 创建拓展
    create extension dblink;

  2. 创建连接
    select dblink_connect(‘myconn’,‘dbname=dbname host=localhost user=username password=123456’);

  3. 执行跨库查询并与当前库数据混合查询
    select * from manager.mediafile where personid in (select * from dblink(‘myconn’,‘select id from manager.person where statedm like ‘‘1%’’’) as t(a varchar));//

  4. 关闭连接
    select dblink_disconnect(‘myconn’);

  5. 关闭拓展
    drop extension dblink;

你可能感兴趣的:(数据库)