1 \connect dblink_test_slave
3 create table foo(f1 int, f2 text, f3 text[], primary key (f1,f2));
4 insert into foo values(0,'a','{"a0","b0","c0"}');
5 insert into foo values(1,'b','{"a1","b1","c1"}');
6 insert into foo values(2,'c','{"a2","b2","c2"}');
7 insert into foo values(3,'d','{"a3","b3","c3"}');
8 insert into foo values(4,'e','{"a4","b4","c4"}');
9 insert into foo values(5,'f','{"a5","b5","c5"}');
10 insert into foo values(6,'g','{"a6","b6","c6"}');
11 insert into foo values(7,'h','{"a7","b7","c7"}');
12 insert into foo values(8,'i','{"a8","b8","c8"}');
13 insert into foo values(9,'j','{"a9","b9","c9"}');
15 \connect dblink_test_master
18 select * from dblink('dbname=dblink_test_slave','select * from foo') as t(a int, b text, c text[]) where t.a > 7;
20 -- should generate "no connection available" error
21 select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7;
23 -- create a persistent connection
24 select dblink_connect('dbname=dblink_test_slave');
26 -- use the persistent connection
27 select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7;
30 select dblink_open('rmt_foo_cursor','select * from foo');
33 select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]);
34 select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]);
36 -- this one only finds two rows left
37 select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]);
40 select dblink_close('rmt_foo_cursor');
42 -- should generate "cursor rmt_foo_cursor does not exist" error
43 select * from dblink_fetch('rmt_foo_cursor',4) as t(a int, b text, c text[]);
45 -- close the persistent connection
46 select dblink_disconnect();
48 -- should generate "no connection available" error
49 select * from dblink('select * from foo') as t(a int, b text, c text[]) where t.a > 7;
51 -- put more data into our slave table, first using arbitrary connection syntax
52 -- but truncate the actual return value so we can use diff to check for success
53 select substr(dblink_exec('dbname=dblink_test_slave','insert into foo values(10,''k'',''{"a10","b10","c10"}'')'),1,6);
55 -- create a persistent connection
56 select dblink_connect('dbname=dblink_test_slave');
58 -- put more data into our slave table, using persistent connection syntax
59 -- but truncate the actual return value so we can use diff to check for success
60 select substr(dblink_exec('insert into foo values(11,''l'',''{"a11","b11","c11"}'')'),1,6);
63 select * from dblink('select * from foo') as t(a int, b text, c text[]);
66 select dblink_exec('update foo set f3[2] = ''b99'' where f1 = 11');
69 select * from dblink('select * from foo') as t(a int, b text, c text[]) where a = 11;
72 select dblink_exec('delete from foo where f1 = 11');
75 select * from dblink('select * from foo') as t(a int, b text, c text[]) where a = 11;
78 \connect dblink_test_slave
80 -- show the currently executing query
81 select 'hello' as hello, dblink_current_query() as query;
83 -- list the primary key fields
84 select * from dblink_get_pkey('foo');
86 -- build an insert statement based on a local tuple,
87 -- replacing the primary key values with new ones
88 select dblink_build_sql_insert('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}');
90 -- build an update statement based on a local tuple,
91 -- replacing the primary key values with new ones
92 select dblink_build_sql_update('foo','1 2',2,'{"0", "a"}','{"99", "xyz"}');
94 -- build a delete statement based on a local tuple,
95 select dblink_build_sql_delete('foo','1 2',2,'{"0", "a"}');