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
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)
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;