mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Added async query capability. Original patch by
Kai Londenberg, modified by Joe Conway
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
$PostgreSQL: pgsql/contrib/dblink/doc/misc,v 1.3 2006/03/11 04:38:29 momjian Exp $
|
||||
$PostgreSQL: pgsql/contrib/dblink/doc/misc,v 1.4 2006/09/02 21:11:15 joe Exp $
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
@ -139,3 +139,94 @@ test=# select dblink_build_sql_update('foo','1 2',2,'{"1", "a"}','{"1", "b"}');
|
||||
UPDATE foo SET f1='1',f2='b',f3='1' WHERE f1='1' AND f2='b'
|
||||
(1 row)
|
||||
|
||||
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
dblink_get_connections -- returns a text array of all active named
|
||||
dblink connections
|
||||
|
||||
Synopsis
|
||||
|
||||
dblink_get_connections() RETURNS text[]
|
||||
|
||||
Inputs
|
||||
|
||||
none
|
||||
|
||||
Outputs
|
||||
|
||||
Returns text array of all active named dblink connections
|
||||
|
||||
Example usage
|
||||
|
||||
SELECT dblink_get_connections();
|
||||
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
dblink_is_busy -- checks to see if named connection is busy
|
||||
with an async query
|
||||
|
||||
Synopsis
|
||||
|
||||
dblink_is_busy(text connname) RETURNS int
|
||||
|
||||
Inputs
|
||||
|
||||
connname
|
||||
The specific connection name to use.
|
||||
|
||||
Outputs
|
||||
|
||||
Returns 1 if connection is busy, 0 if it is not busy.
|
||||
If this function returns 0, it is guaranteed that dblink_get_result
|
||||
will not block.
|
||||
|
||||
Example usage
|
||||
|
||||
SELECT dblink_is_busy('dtest1');
|
||||
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
dblink_cancel_query -- cancels any active query on the named connection
|
||||
|
||||
Synopsis
|
||||
|
||||
dblink_cancel_query(text connname) RETURNS text
|
||||
|
||||
Inputs
|
||||
|
||||
connname
|
||||
The specific connection name to use.
|
||||
|
||||
Outputs
|
||||
|
||||
Returns "OK" on success, or an error message on failure.
|
||||
|
||||
Example usage
|
||||
|
||||
SELECT dblink_cancel_query('dtest1');
|
||||
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
dblink_error_message -- gets last error message on the named connection
|
||||
|
||||
Synopsis
|
||||
|
||||
dblink_error_message(text connname) RETURNS text
|
||||
|
||||
Inputs
|
||||
|
||||
connname
|
||||
The specific connection name to use.
|
||||
|
||||
Outputs
|
||||
|
||||
Returns last error message.
|
||||
|
||||
Example usage
|
||||
|
||||
SELECT dblink_error_message('dtest1');
|
||||
|
@ -118,3 +118,125 @@ Then you can simply write:
|
||||
|
||||
select * from myremote_pg_proc where proname like 'bytea%';
|
||||
|
||||
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
dblink_send_query -- Sends an async query to a remote database
|
||||
|
||||
Synopsis
|
||||
|
||||
dblink_send_query(text connname, text sql)
|
||||
|
||||
Inputs
|
||||
|
||||
connname
|
||||
The specific connection name to use.
|
||||
|
||||
sql
|
||||
|
||||
sql statement that you wish to execute on the remote host
|
||||
e.g. "select * from pg_class"
|
||||
|
||||
Outputs
|
||||
|
||||
Returns int. A return value of 1 if the query was successfully dispatched,
|
||||
0 otherwise. If 1, results must be fetched by dblink_get_result(connname).
|
||||
A running query may be cancelled by dblink_cancel_query(connname).
|
||||
|
||||
Example usage
|
||||
|
||||
SELECT dblink_connect('dtest1', 'dbname=contrib_regression');
|
||||
SELECT * from
|
||||
dblink_send_query('dtest1', 'select * from foo where f1 < 3') as t1;
|
||||
|
||||
==================================================================
|
||||
Name
|
||||
|
||||
dblink_get_result -- Gets an async query result
|
||||
|
||||
Synopsis
|
||||
|
||||
dblink_get_result(text connname [, bool fail_on_error])
|
||||
|
||||
Inputs
|
||||
|
||||
connname
|
||||
The specific connection name to use. An asynchronous query must
|
||||
have already been sent using dblink_send_query()
|
||||
|
||||
fail_on_error
|
||||
|
||||
If true (default when not present) then an ERROR thrown on the remote side
|
||||
of the connection causes an ERROR to also be thrown locally. If false, the
|
||||
remote ERROR is locally treated as a NOTICE, and no rows are returned.
|
||||
|
||||
Outputs
|
||||
|
||||
Returns setof record
|
||||
|
||||
Notes
|
||||
Blocks until a result gets available.
|
||||
|
||||
This function *must* be called if dblink_send_query returned
|
||||
a 1, even on cancelled queries - otherwise the connection
|
||||
can't be used anymore. It must be called once for each query
|
||||
sent, and one additional time to obtain an empty set result,
|
||||
prior to using the connection again.
|
||||
|
||||
Example usage
|
||||
|
||||
contrib_regression=# SELECT dblink_connect('dtest1', 'dbname=contrib_regression');
|
||||
dblink_connect
|
||||
----------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
contrib_regression=# SELECT * from
|
||||
contrib_regression-# dblink_send_query('dtest1', 'select * from foo where f1 < 3') as t1;
|
||||
t1
|
||||
----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
contrib_regression=# SELECT * from dblink_get_result('dtest1') as t1(f1 int, f2 text, f3 text[]);
|
||||
f1 | f2 | f3
|
||||
----+----+------------
|
||||
0 | a | {a0,b0,c0}
|
||||
1 | b | {a1,b1,c1}
|
||||
2 | c | {a2,b2,c2}
|
||||
(3 rows)
|
||||
|
||||
contrib_regression=# SELECT * from dblink_get_result('dtest1') as t1(f1 int, f2 text, f3 text[]);
|
||||
f1 | f2 | f3
|
||||
----+----+----
|
||||
(0 rows)
|
||||
|
||||
contrib_regression=# SELECT * from
|
||||
dblink_send_query('dtest1', 'select * from foo where f1 < 3; select * from foo where f1 > 6') as t1;
|
||||
t1
|
||||
----
|
||||
1
|
||||
(1 row)
|
||||
|
||||
contrib_regression=# SELECT * from dblink_get_result('dtest1') as t1(f1 int, f2 text, f3 text[]);
|
||||
f1 | f2 | f3
|
||||
----+----+------------
|
||||
0 | a | {a0,b0,c0}
|
||||
1 | b | {a1,b1,c1}
|
||||
2 | c | {a2,b2,c2}
|
||||
(3 rows)
|
||||
|
||||
contrib_regression=# SELECT * from dblink_get_result('dtest1') as t1(f1 int, f2 text, f3 text[]);
|
||||
f1 | f2 | f3
|
||||
----+----+---------------
|
||||
7 | h | {a7,b7,c7}
|
||||
8 | i | {a8,b8,c8}
|
||||
9 | j | {a9,b9,c9}
|
||||
10 | k | {a10,b10,c10}
|
||||
(4 rows)
|
||||
|
||||
contrib_regression=# SELECT * from dblink_get_result('dtest1') as t1(f1 int, f2 text, f3 text[]);
|
||||
f1 | f2 | f3
|
||||
----+----+----
|
||||
(0 rows)
|
||||
|
Reference in New Issue
Block a user