Please apply attached patch to contrib/dblink. It adds named persistent
connections to dblink. Shridhar Daithanka
This commit is contained in:
parent
92798de02e
commit
8f337e86cd
contrib/dblink
@ -4,8 +4,11 @@
|
||||
* Functions returning results from a remote database
|
||||
*
|
||||
* Joe Conway <mail@joeconway.com>
|
||||
* And contributors:
|
||||
* Darko Prenosil <Darko.Prenosil@finteh.hr>
|
||||
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
|
||||
*
|
||||
* Copyright (c) 2001, 2002 by PostgreSQL Global Development Group
|
||||
* Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
|
||||
* ALL RIGHTS RESERVED;
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
@ -27,14 +30,16 @@
|
||||
*
|
||||
*/
|
||||
|
||||
Version 0.5 (25 August, 2002):
|
||||
Major overhaul to work with new backend "table function" capability. Removed
|
||||
dblink_strtok() and dblink_replace() functions because they are now
|
||||
available as backend functions (split() and replace() respectively).
|
||||
Tested under Linux (Red Hat 7.3) and PostgreSQL 7.3devel. This version
|
||||
is no longer backwards portable to PostgreSQL 7.2.
|
||||
Version 0.6 (14 June, 2003):
|
||||
Completely removed previously deprecated functions. Added ability
|
||||
to create "named" persistent connections in addition to the single global
|
||||
"unnamed" persistent connection.
|
||||
Tested under Linux (Red Hat 9) and PostgreSQL 7.4devel.
|
||||
|
||||
Release Notes:
|
||||
Version 0.6
|
||||
- functions deprecated in 0.5 have been removed
|
||||
- added ability to create "named" persistent connections
|
||||
Version 0.5
|
||||
- dblink now supports use directly as a table function; this is the new
|
||||
preferred usage going forward
|
||||
@ -87,35 +92,51 @@ Installation:
|
||||
connection
|
||||
------------
|
||||
dblink_connect(text) RETURNS text
|
||||
- opens a connection that will persist for duration of current
|
||||
- opens an unnamed connection that will persist for duration of
|
||||
current backend or until it is disconnected
|
||||
dblink_connect(text,text) RETURNS text
|
||||
- opens a named connection that will persist for duration of current
|
||||
backend or until it is disconnected
|
||||
dblink_disconnect() RETURNS text
|
||||
- disconnects a persistent connection
|
||||
- disconnects the unnamed persistent connection
|
||||
dblink_disconnect(text) RETURNS text
|
||||
- disconnects a named persistent connection
|
||||
|
||||
cursor
|
||||
------------
|
||||
dblink_open(text,text) RETURNS text
|
||||
- opens a cursor using connection already opened with dblink_connect()
|
||||
that will persist for duration of current backend or until it is
|
||||
closed
|
||||
- opens a cursor using unnamed connection already opened with
|
||||
dblink_connect() that will persist for duration of current backend
|
||||
or until it is closed
|
||||
dblink_open(text,text,text) RETURNS text
|
||||
- opens a cursor using a named connection already opened with
|
||||
dblink_connect() that will persist for duration of current backend
|
||||
or until it is closed
|
||||
dblink_fetch(text, int) RETURNS setof record
|
||||
- fetches data from an already opened cursor
|
||||
- fetches data from an already opened cursor on the unnamed connection
|
||||
dblink_fetch(text, text, int) RETURNS setof record
|
||||
- fetches data from an already opened cursor on a named connection
|
||||
dblink_close(text) RETURNS text
|
||||
- closes a cursor
|
||||
- closes a cursor on the unnamed connection
|
||||
dblink_close(text,text) RETURNS text
|
||||
- closes a cursor on a named connection
|
||||
|
||||
query
|
||||
------------
|
||||
dblink(text,text) RETURNS setof record
|
||||
- returns a set of results from remote SELECT query
|
||||
(Note: comment out in dblink.sql to use deprecated version)
|
||||
- returns a set of results from remote SELECT query; the first argument
|
||||
is either a connection string, or the name of an already opened
|
||||
persistant connection
|
||||
dblink(text) RETURNS setof record
|
||||
- returns a set of results from remote SELECT query, using connection
|
||||
already opened with dblink_connect()
|
||||
- returns a set of results from remote SELECT query, using the unnamed
|
||||
connection already opened with dblink_connect()
|
||||
|
||||
execute
|
||||
------------
|
||||
dblink_exec(text, text) RETURNS text
|
||||
- executes an INSERT/UPDATE/DELETE query remotely
|
||||
- executes an INSERT/UPDATE/DELETE query remotely; the first argument
|
||||
is either a connection string, or the name of an already opened
|
||||
persistant connection
|
||||
dblink_exec(text) RETURNS text
|
||||
- executes an INSERT/UPDATE/DELETE query remotely, using connection
|
||||
already opened with dblink_connect()
|
||||
@ -136,19 +157,6 @@ Installation:
|
||||
- builds an update statement using a local tuple, replacing the
|
||||
selection key field values with alternate supplied values
|
||||
|
||||
Not installed by default
|
||||
deprecated
|
||||
------------
|
||||
dblink(text,text) RETURNS setof int
|
||||
- *DEPRECATED* returns a resource id for results from remote query
|
||||
(Note: must uncomment in dblink.sql to use)
|
||||
dblink_tok(int,int) RETURNS text
|
||||
- *DEPRECATED* extracts and returns individual field results; used
|
||||
only in conjunction with the *DEPRECATED* form of dblink
|
||||
(Note: must uncomment in dblink.sql to use)
|
||||
dblink_last_oid(int) RETURNS oid
|
||||
- *DEPRECATED* returns the last inserted oid
|
||||
|
||||
Documentation:
|
||||
|
||||
Note: Parameters representing relation names must include double
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -4,8 +4,11 @@
|
||||
* Functions returning results from a remote database
|
||||
*
|
||||
* Joe Conway <mail@joeconway.com>
|
||||
* And contributors:
|
||||
* Darko Prenosil <Darko.Prenosil@finteh.hr>
|
||||
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
|
||||
*
|
||||
* Copyright (c) 2001, 2002 by PostgreSQL Global Development Group
|
||||
* Copyright (c) 2001, 2002, 2003 by PostgreSQL Global Development Group
|
||||
* ALL RIGHTS RESERVED;
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software and its
|
||||
@ -30,36 +33,9 @@
|
||||
#ifndef DBLINK_H
|
||||
#define DBLINK_H
|
||||
|
||||
/*
|
||||
* This struct holds the results of the remote query.
|
||||
* Use fn_extra to hold a pointer to it across calls
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/*
|
||||
* last tuple number accessed
|
||||
*/
|
||||
int tup_num;
|
||||
|
||||
/*
|
||||
* resource index number for this context
|
||||
*/
|
||||
int res_id_index;
|
||||
|
||||
/*
|
||||
* the actual query results
|
||||
*/
|
||||
PGresult *res;
|
||||
} dblink_results;
|
||||
|
||||
/*
|
||||
* External declarations
|
||||
*/
|
||||
/* deprecated */
|
||||
extern Datum dblink(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_tok(PG_FUNCTION_ARGS);
|
||||
|
||||
/* supported */
|
||||
extern Datum dblink_connect(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_disconnect(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_open(PG_FUNCTION_ARGS);
|
||||
@ -68,7 +44,6 @@ extern Datum dblink_fetch(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_record(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_exec(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_get_pkey(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_last_oid(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_build_sql_insert(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_build_sql_delete(PG_FUNCTION_ARGS);
|
||||
extern Datum dblink_build_sql_update(PG_FUNCTION_ARGS);
|
||||
|
@ -1,50 +1,53 @@
|
||||
--
|
||||
-- Uncomment the following commented lines to use original DEPRECATED functions
|
||||
--
|
||||
--CREATE OR REPLACE FUNCTION dblink (text,text)
|
||||
--RETURNS setof int
|
||||
--AS 'MODULE_PATHNAME','dblink'
|
||||
--LANGUAGE 'C' WITH (isstrict);
|
||||
--CREATE OR REPLACE FUNCTION dblink_tok (int,int)
|
||||
--RETURNS text
|
||||
--AS 'MODULE_PATHNAME','dblink_tok'
|
||||
--LANGUAGE 'C' WITH (isstrict);
|
||||
--CREATE OR REPLACE FUNCTION dblink_last_oid (int)
|
||||
--RETURNS oid
|
||||
--AS 'MODULE_PATHNAME','dblink_last_oid'
|
||||
--LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_connect (text)
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME','dblink_connect'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_connect (text, text)
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME','dblink_connect'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_disconnect ()
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME','dblink_disconnect'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_disconnect (text)
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME','dblink_disconnect'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_open (text,text)
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME','dblink_open'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_open (text,text,text)
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME','dblink_open'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_fetch (text,int)
|
||||
RETURNS setof record
|
||||
AS 'MODULE_PATHNAME','dblink_fetch'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_fetch (text,text,int)
|
||||
RETURNS setof record
|
||||
AS 'MODULE_PATHNAME','dblink_fetch'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
CREATE OR REPLACE FUNCTION dblink_close (text)
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME','dblink_close'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
-- Note: if this is not a first time install of dblink, uncomment the
|
||||
-- following DROP which prepares the database for the new, non-deprecated
|
||||
-- version.
|
||||
--DROP FUNCTION dblink (text,text);
|
||||
CREATE OR REPLACE FUNCTION dblink_close (text,text)
|
||||
RETURNS text
|
||||
AS 'MODULE_PATHNAME','dblink_close'
|
||||
LANGUAGE 'C' WITH (isstrict);
|
||||
|
||||
-- Comment out the following 3 lines if the DEPRECATED functions are used.
|
||||
CREATE OR REPLACE FUNCTION dblink (text,text)
|
||||
RETURNS setof record
|
||||
AS 'MODULE_PATHNAME','dblink_record'
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
||||
|
@ -106,11 +106,11 @@ WHERE t.a > 7;
|
||||
9 | j | {a9,b9,c9}
|
||||
(2 rows)
|
||||
|
||||
-- should generate "no connection available" error
|
||||
-- should generate "connection not available" error
|
||||
SELECT *
|
||||
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
ERROR: dblink: no connection available
|
||||
ERROR: dblink_record: connection not available
|
||||
-- create a persistent connection
|
||||
SELECT dblink_connect('dbname=regression');
|
||||
dblink_connect
|
||||
@ -172,10 +172,10 @@ SELECT dblink_close('rmt_foo_cursor');
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- should generate "cursor rmt_foo_cursor does not exist" error
|
||||
-- should generate "cursor not found: rmt_foo_cursor" error
|
||||
SELECT *
|
||||
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
ERROR: dblink_fetch: cursor rmt_foo_cursor does not exist
|
||||
ERROR: dblink_fetch: cursor not found: rmt_foo_cursor
|
||||
-- close the persistent connection
|
||||
SELECT dblink_disconnect();
|
||||
dblink_disconnect
|
||||
@ -183,11 +183,12 @@ SELECT dblink_disconnect();
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- should generate "no connection available" error
|
||||
-- should generate "no connection to the server" error
|
||||
SELECT *
|
||||
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
ERROR: dblink: no connection available
|
||||
ERROR: dblink: sql error: no connection to the server
|
||||
|
||||
-- put more data into our slave table, first using arbitrary connection syntax
|
||||
-- but truncate the actual return value so we can use diff to check for success
|
||||
SELECT substr(dblink_exec('dbname=regression','INSERT INTO foo VALUES(10,''k'',''{"a10","b10","c10"}'')'),1,6);
|
||||
@ -268,3 +269,198 @@ SELECT dblink_disconnect();
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
--
|
||||
-- tests for the new named persistent connection syntax
|
||||
--
|
||||
-- should generate "missing "=" after "myconn" in connection info string" error
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
ERROR: dblink: connection error: missing "=" after "myconn" in connection info string
|
||||
|
||||
-- create a named persistent connection
|
||||
SELECT dblink_connect('myconn','dbname=regression');
|
||||
dblink_connect
|
||||
----------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- use the named persistent connection
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
a | b | c
|
||||
----+---+---------------
|
||||
8 | i | {a8,b8,c8}
|
||||
9 | j | {a9,b9,c9}
|
||||
10 | k | {a10,b10,c10}
|
||||
(3 rows)
|
||||
|
||||
-- create a second named persistent connection
|
||||
-- should error with "cannot save named connection"
|
||||
SELECT dblink_connect('myconn','dbname=regression');
|
||||
NOTICE: cannot use a connection name more than once
|
||||
ERROR: dblink_connect: cannot save named connection
|
||||
-- create a second named persistent connection with a new name
|
||||
SELECT dblink_connect('myconn2','dbname=regression');
|
||||
dblink_connect
|
||||
----------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- use the second named persistent connection
|
||||
SELECT *
|
||||
FROM dblink('myconn2','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
a | b | c
|
||||
----+---+---------------
|
||||
8 | i | {a8,b8,c8}
|
||||
9 | j | {a9,b9,c9}
|
||||
10 | k | {a10,b10,c10}
|
||||
(3 rows)
|
||||
|
||||
-- close the second named persistent connection
|
||||
SELECT dblink_disconnect('myconn2');
|
||||
dblink_disconnect
|
||||
-------------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- open a cursor
|
||||
SELECT dblink_open('myconn','rmt_foo_cursor','SELECT * FROM foo');
|
||||
dblink_open
|
||||
-------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- fetch some data
|
||||
SELECT *
|
||||
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
a | b | c
|
||||
---+---+------------
|
||||
0 | a | {a0,b0,c0}
|
||||
1 | b | {a1,b1,c1}
|
||||
2 | c | {a2,b2,c2}
|
||||
3 | d | {a3,b3,c3}
|
||||
(4 rows)
|
||||
|
||||
SELECT *
|
||||
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
a | b | c
|
||||
---+---+------------
|
||||
4 | e | {a4,b4,c4}
|
||||
5 | f | {a5,b5,c5}
|
||||
6 | g | {a6,b6,c6}
|
||||
7 | h | {a7,b7,c7}
|
||||
(4 rows)
|
||||
|
||||
-- this one only finds three rows left
|
||||
SELECT *
|
||||
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
a | b | c
|
||||
----+---+---------------
|
||||
8 | i | {a8,b8,c8}
|
||||
9 | j | {a9,b9,c9}
|
||||
10 | k | {a10,b10,c10}
|
||||
(3 rows)
|
||||
|
||||
-- close the cursor
|
||||
SELECT dblink_close('myconn','rmt_foo_cursor');
|
||||
dblink_close
|
||||
--------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- should generate "cursor not found: rmt_foo_cursor" error
|
||||
SELECT *
|
||||
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
ERROR: dblink_fetch: cursor not found: rmt_foo_cursor
|
||||
-- close the named persistent connection
|
||||
SELECT dblink_disconnect('myconn');
|
||||
dblink_disconnect
|
||||
-------------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- should generate "missing "=" after "myconn" in connection info string" error
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
ERROR: dblink: connection error: missing "=" after "myconn" in connection info string
|
||||
|
||||
-- create a named persistent connection
|
||||
SELECT dblink_connect('myconn','dbname=regression');
|
||||
dblink_connect
|
||||
----------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- put more data into our slave table, using named persistent connection syntax
|
||||
-- but truncate the actual return value so we can use diff to check for success
|
||||
SELECT substr(dblink_exec('myconn','INSERT INTO foo VALUES(11,''l'',''{"a11","b11","c11"}'')'),1,6);
|
||||
substr
|
||||
--------
|
||||
INSERT
|
||||
(1 row)
|
||||
|
||||
-- let's see it
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[]);
|
||||
a | b | c
|
||||
----+---+---------------
|
||||
0 | a | {a0,b0,c0}
|
||||
1 | b | {a1,b1,c1}
|
||||
2 | c | {a2,b2,c2}
|
||||
3 | d | {a3,b3,c3}
|
||||
4 | e | {a4,b4,c4}
|
||||
5 | f | {a5,b5,c5}
|
||||
6 | g | {a6,b6,c6}
|
||||
7 | h | {a7,b7,c7}
|
||||
8 | i | {a8,b8,c8}
|
||||
9 | j | {a9,b9,c9}
|
||||
10 | k | {a10,b10,c10}
|
||||
11 | l | {a11,b11,c11}
|
||||
(12 rows)
|
||||
|
||||
-- change some data
|
||||
SELECT dblink_exec('myconn','UPDATE foo SET f3[2] = ''b99'' WHERE f1 = 11');
|
||||
dblink_exec
|
||||
-------------
|
||||
UPDATE 1
|
||||
(1 row)
|
||||
|
||||
-- let's see it
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE a = 11;
|
||||
a | b | c
|
||||
----+---+---------------
|
||||
11 | l | {a11,b99,c11}
|
||||
(1 row)
|
||||
|
||||
-- delete some data
|
||||
SELECT dblink_exec('myconn','DELETE FROM foo WHERE f1 = 11');
|
||||
dblink_exec
|
||||
-------------
|
||||
DELETE 1
|
||||
(1 row)
|
||||
|
||||
-- let's see it
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE a = 11;
|
||||
a | b | c
|
||||
---+---+---
|
||||
(0 rows)
|
||||
|
||||
-- close the named persistent connection
|
||||
SELECT dblink_disconnect('myconn');
|
||||
dblink_disconnect
|
||||
-------------------
|
||||
OK
|
||||
(1 row)
|
||||
|
||||
-- close the named persistent connection again
|
||||
-- should get "connection named "myconn" not found" error
|
||||
SELECT dblink_disconnect('myconn');
|
||||
ERROR: dblink_disconnect: connection named "myconn" not found
|
||||
|
@ -68,7 +68,7 @@ SELECT *
|
||||
FROM dblink('dbname=regression','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
|
||||
-- should generate "no connection available" error
|
||||
-- should generate "connection not available" error
|
||||
SELECT *
|
||||
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
@ -98,14 +98,14 @@ FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
-- close the cursor
|
||||
SELECT dblink_close('rmt_foo_cursor');
|
||||
|
||||
-- should generate "cursor rmt_foo_cursor does not exist" error
|
||||
-- should generate "cursor not found: rmt_foo_cursor" error
|
||||
SELECT *
|
||||
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
|
||||
-- close the persistent connection
|
||||
SELECT dblink_disconnect();
|
||||
|
||||
-- should generate "no connection available" error
|
||||
-- should generate "no connection to the server" error
|
||||
SELECT *
|
||||
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
@ -143,3 +143,98 @@ WHERE a = 11;
|
||||
|
||||
-- close the persistent connection
|
||||
SELECT dblink_disconnect();
|
||||
|
||||
--
|
||||
-- tests for the new named persistent connection syntax
|
||||
--
|
||||
|
||||
-- should generate "missing "=" after "myconn" in connection info string" error
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
|
||||
-- create a named persistent connection
|
||||
SELECT dblink_connect('myconn','dbname=regression');
|
||||
|
||||
-- use the named persistent connection
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
|
||||
-- create a second named persistent connection
|
||||
-- should error with "cannot save named connection"
|
||||
SELECT dblink_connect('myconn','dbname=regression');
|
||||
|
||||
-- create a second named persistent connection with a new name
|
||||
SELECT dblink_connect('myconn2','dbname=regression');
|
||||
|
||||
-- use the second named persistent connection
|
||||
SELECT *
|
||||
FROM dblink('myconn2','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
|
||||
-- close the second named persistent connection
|
||||
SELECT dblink_disconnect('myconn2');
|
||||
|
||||
-- open a cursor
|
||||
SELECT dblink_open('myconn','rmt_foo_cursor','SELECT * FROM foo');
|
||||
|
||||
-- fetch some data
|
||||
SELECT *
|
||||
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
|
||||
SELECT *
|
||||
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
|
||||
-- this one only finds three rows left
|
||||
SELECT *
|
||||
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
|
||||
-- close the cursor
|
||||
SELECT dblink_close('myconn','rmt_foo_cursor');
|
||||
|
||||
-- should generate "cursor not found: rmt_foo_cursor" error
|
||||
SELECT *
|
||||
FROM dblink_fetch('myconn','rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||
|
||||
-- close the named persistent connection
|
||||
SELECT dblink_disconnect('myconn');
|
||||
|
||||
-- should generate "missing "=" after "myconn" in connection info string" error
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE t.a > 7;
|
||||
|
||||
-- create a named persistent connection
|
||||
SELECT dblink_connect('myconn','dbname=regression');
|
||||
|
||||
-- put more data into our slave table, using named persistent connection syntax
|
||||
-- but truncate the actual return value so we can use diff to check for success
|
||||
SELECT substr(dblink_exec('myconn','INSERT INTO foo VALUES(11,''l'',''{"a11","b11","c11"}'')'),1,6);
|
||||
|
||||
-- let's see it
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[]);
|
||||
|
||||
-- change some data
|
||||
SELECT dblink_exec('myconn','UPDATE foo SET f3[2] = ''b99'' WHERE f1 = 11');
|
||||
|
||||
-- let's see it
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE a = 11;
|
||||
|
||||
-- delete some data
|
||||
SELECT dblink_exec('myconn','DELETE FROM foo WHERE f1 = 11');
|
||||
|
||||
-- let's see it
|
||||
SELECT *
|
||||
FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||
WHERE a = 11;
|
||||
|
||||
-- close the named persistent connection
|
||||
SELECT dblink_disconnect('myconn');
|
||||
|
||||
-- close the named persistent connection again
|
||||
-- should get "connection named "myconn" not found" error
|
||||
SELECT dblink_disconnect('myconn');
|
||||
|
Loading…
x
Reference in New Issue
Block a user