lottu01=> SELECT * FROM dblink('lottu', 'select id, info from public.t1') as lottu_t1(id int, info text);
id | info
------+-------
1001 | lottu
(1 row)
我们也可以直接使用;无需先创建dblink_connect。这是常用的方式。
lottu01=> SELECT * FROM dblink('host=192.168.1.221 port=6000 user=lottu password=li0924 dbname=lottu', 'select id, info from public.t1') as lottu_t1(id int, info text);
id | info
------+-------
1001 | lottu
(1 row)
lottu01=> create temp table lottu_t1 as SELECT * FROM dblink('host=192.168.1.221 port=6000 user=lottu password=li0924 dbname=lottu', 'select id, info from public.t1') as lottu_t1(id int, info text);
SELECT 2
lottu01=> select * from lottu_t1;
id | info
------+-------
1001 | lottu
1002 | hello
(2 rows)