Specify dblink column definition list from a local existing type

孤者浪人 提交于 2019-12-01 03:18:31

You might need to make sure that your types are always in sync but this should work:

SELECT (t1::test).* 
  FROM dblink('dbname=remote', 'select * from test') AS t1;

The key is that often you need parentheses to ensure that the parser knows you are dealing with tuples.

For example this works for me:

 CREATE TABLE test (id int, test bool);
 select (t1::test).* from (select 1, true) t1;

But this throws a syntax error:

 select t1::test.* from (select 1, true) t1;

Try something like this :

select (rec).* from dblink('dbname=...','select myalias from foreign_table
  myalias') t1 (rec local_type)

Example (get tables stats from other database) :

select (rec).* from dblink('dbname=foreignDb','select t1 from
  pg_stat_all_tables t1') t2 (rec pg_stat_all_tables)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!