Specify dblink column definition list from a local existing type

后端 未结 2 766
离开以前
离开以前 2021-01-11 13:11

I am using dblink to move certain data between databases. Everything is save and sound but I am wondering if there is a more convenient way to define the column definition l

2条回答
  •  长情又很酷
    2021-01-11 13:59

    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;
    

提交回复
热议问题