1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Please apply attached patch to contrib/dblink. It adds named persistent

connections to dblink.

Shridhar Daithanka
This commit is contained in:
Bruce Momjian
2003-06-25 01:10:15 +00:00
parent 92798de02e
commit 8f337e86cd
10 changed files with 857 additions and 616 deletions

View File

@ -6,21 +6,35 @@ dblink_connect -- Opens a persistent connection to a remote database
Synopsis
dblink_connect(text connstr)
dblink_connect(text connname, text connstr)
Inputs
connname
if 2 arguments are given, the first is used as a name for a persistent
connection
connstr
standard libpq format connection string,
e.g. "hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd"
if only one argument is given, the connection is unnamed; only one unnamed
connection can exist at a time
Outputs
Returns status = "OK"
Example usage
test=# select dblink_connect('dbname=template1');
select dblink_connect('dbname=template1');
dblink_connect
----------------
OK
(1 row)
select dblink_connect('myconn','dbname=template1');
dblink_connect
----------------
OK
@ -29,15 +43,18 @@ test=# select dblink_connect('dbname=template1');
==================================================================
Name
dblink_disconnect -- Closes the persistent connection to a remote database
dblink_disconnect -- Closes a persistent connection to a remote database
Synopsis
dblink_disconnect()
dblink_disconnect(text connname)
Inputs
none
connname
if an argument is given, it is used as a name for a persistent
connection to close; otherwiase the unnamed connection is closed
Outputs
@ -51,3 +68,8 @@ test=# select dblink_disconnect();
OK
(1 row)
select dblink_disconnect('myconn');
dblink_disconnect
-------------------
OK
(1 row)

View File

@ -6,9 +6,14 @@ dblink_open -- Opens a cursor on a remote database
Synopsis
dblink_open(text cursorname, text sql)
dblink_open(text connname, text cursorname, text sql)
Inputs
connname
if three arguments are present, the first is taken as the specific
connection name to use; otherwise the unnamed connection is assumed
cursorname
a reference name for the cursor
@ -52,9 +57,14 @@ dblink_fetch -- Returns a set from an open cursor on a remote database
Synopsis
dblink_fetch(text cursorname, int32 howmany)
dblink_fetch(text connname, text cursorname, int32 howmany)
Inputs
connname
if three arguments are present, the first is taken as the specific
connection name to use; otherwise the unnamed connection is assumed
cursorname
The reference name for the cursor
@ -123,9 +133,14 @@ dblink_close -- Closes a cursor on a remote database
Synopsis
dblink_close(text cursorname)
dblink_close(text connname, text cursorname)
Inputs
connname
if two arguments are present, the first is taken as the specific
connection name to use; otherwise the unnamed connection is assumed
cursorname
a reference name for the cursor
@ -135,7 +150,8 @@ Outputs
Returns status = "OK"
Note
dblink_connect(text connstr) must be executed first.
dblink_connect(text connstr) or dblink_connect(text connname, text connstr)
must be executed first.
Example usage
@ -157,3 +173,20 @@ test=# select dblink_close('foo');
OK
(1 row)
select dblink_connect('myconn','dbname=regression');
dblink_connect
----------------
OK
(1 row)
select dblink_open('myconn','foo','select proname, prosrc from pg_proc');
dblink_open
-------------
OK
(1 row)
select dblink_close('myconn','foo');
dblink_close
--------------
OK
(1 row)

View File

@ -6,22 +6,23 @@ dblink_exec -- Executes an UPDATE/INSERT/DELETE on a remote database
Synopsis
dblink_exec(text connstr, text sql)
- or -
dblink_exec(text connname, text sql)
dblink_exec(text sql)
Inputs
connname
connstr
If two arguments are present, the first is first assumed to be a specific
connection name to use. If the name is not found, the argument is then
assumed to be a valid connection string, of standard libpq format,
e.g.: "hostaddr=127.0.0.1 dbname=mydb user=postgres password=mypasswd"
standard libpq format connection string,
e.g. "hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd"
If the second form is used, then the dblink_connect(text connstr) must be
executed first.
If only one argument is used, then the unnamed connection is used.
sql
sql statement that you wish to execute on the remote host, e.g.:
insert into foo values(0,'a','{"a0","b0","c0"}');
Outputs
@ -36,14 +37,26 @@ Notes
Example usage
test=# select dblink_connect('dbname=dblink_test_slave');
select dblink_connect('dbname=dblink_test_slave');
dblink_connect
----------------
OK
(1 row)
test=# select dblink_exec('insert into foo values(21,''z'',''{"a0","b0","c0"}'');');
select dblink_exec('insert into foo values(21,''z'',''{"a0","b0","c0"}'');');
dblink_exec
-----------------
INSERT 943366 1
(1 row)
select dblink_connect('myconn','dbname=regression');
dblink_connect
----------------
OK
(1 row)
select dblink_exec('myconn','insert into foo values(21,''z'',''{"a0","b0","c0"}'');');
dblink_exec
------------------
INSERT 6432584 1
(1 row)

View File

@ -6,17 +6,19 @@ dblink -- Returns a set from a remote database
Synopsis
dblink(text connstr, text sql)
- or -
dblink(text connname, text sql)
dblink(text sql)
Inputs
connname
connstr
If two arguments are present, the first is first assumed to be a specific
connection name to use. If the name is not found, the argument is then
assumed to be a valid connection string, of standard libpq format,
e.g.: "hostaddr=127.0.0.1 dbname=mydb user=postgres password=mypasswd"
standard libpq format connection string,
e.g. "hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd"
If the second form is used, then the dblink_connect(text connstr) must be
executed first.
If only one argument is used, then the unnamed connection is used.
sql
@ -29,7 +31,7 @@ Outputs
Example usage
test=# select * from dblink('dbname=template1','select proname, prosrc from pg_proc')
select * from dblink('dbname=template1','select proname, prosrc from pg_proc')
as t1(proname name, prosrc text) where proname like 'bytea%';
proname | prosrc
------------+------------
@ -47,13 +49,13 @@ test=# select * from dblink('dbname=template1','select proname, prosrc from pg_p
byteaout | byteaout
(12 rows)
test=# select dblink_connect('dbname=template1');
select dblink_connect('dbname=template1');
dblink_connect
----------------
OK
(1 row)
test=# select * from dblink('select proname, prosrc from pg_proc')
select * from dblink('select proname, prosrc from pg_proc')
as t1(proname name, prosrc text) where proname like 'bytea%';
proname | prosrc
------------+------------
@ -71,6 +73,33 @@ test=# select * from dblink('select proname, prosrc from pg_proc')
byteaout | byteaout
(12 rows)
select dblink_connect('myconn','dbname=regression');
dblink_connect
----------------
OK
(1 row)
select * from dblink('myconn','select proname, prosrc from pg_proc')
as t1(proname name, prosrc text) where proname like 'bytea%';
proname | prosrc
------------+------------
bytearecv | bytearecv
byteasend | byteasend
byteale | byteale
byteagt | byteagt
byteage | byteage
byteane | byteane
byteacmp | byteacmp
bytealike | bytealike
byteanlike | byteanlike
byteacat | byteacat
byteaeq | byteaeq
bytealt | bytealt
byteain | byteain
byteaout | byteaout
(14 rows)
==================================================================
A more convenient way to use dblink may be to create a view: