mirror of
https://github.com/postgres/postgres.git
synced 2025-05-13 01:13:08 -04:00
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
@ -4,8 +4,11 @@
|
|||||||
* Functions returning results from a remote database
|
* Functions returning results from a remote database
|
||||||
*
|
*
|
||||||
* Joe Conway <mail@joeconway.com>
|
* 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;
|
* ALL RIGHTS RESERVED;
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
@ -27,14 +30,16 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Version 0.5 (25 August, 2002):
|
Version 0.6 (14 June, 2003):
|
||||||
Major overhaul to work with new backend "table function" capability. Removed
|
Completely removed previously deprecated functions. Added ability
|
||||||
dblink_strtok() and dblink_replace() functions because they are now
|
to create "named" persistent connections in addition to the single global
|
||||||
available as backend functions (split() and replace() respectively).
|
"unnamed" persistent connection.
|
||||||
Tested under Linux (Red Hat 7.3) and PostgreSQL 7.3devel. This version
|
Tested under Linux (Red Hat 9) and PostgreSQL 7.4devel.
|
||||||
is no longer backwards portable to PostgreSQL 7.2.
|
|
||||||
|
|
||||||
Release Notes:
|
Release Notes:
|
||||||
|
Version 0.6
|
||||||
|
- functions deprecated in 0.5 have been removed
|
||||||
|
- added ability to create "named" persistent connections
|
||||||
Version 0.5
|
Version 0.5
|
||||||
- dblink now supports use directly as a table function; this is the new
|
- dblink now supports use directly as a table function; this is the new
|
||||||
preferred usage going forward
|
preferred usage going forward
|
||||||
@ -87,35 +92,51 @@ Installation:
|
|||||||
connection
|
connection
|
||||||
------------
|
------------
|
||||||
dblink_connect(text) RETURNS text
|
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
|
backend or until it is disconnected
|
||||||
dblink_disconnect() RETURNS text
|
dblink_disconnect() RETURNS text
|
||||||
- disconnects a persistent connection
|
- disconnects the unnamed persistent connection
|
||||||
|
dblink_disconnect(text) RETURNS text
|
||||||
|
- disconnects a named persistent connection
|
||||||
|
|
||||||
cursor
|
cursor
|
||||||
------------
|
------------
|
||||||
dblink_open(text,text) RETURNS text
|
dblink_open(text,text) RETURNS text
|
||||||
- opens a cursor using connection already opened with dblink_connect()
|
- opens a cursor using unnamed connection already opened with
|
||||||
that will persist for duration of current backend or until it is
|
dblink_connect() that will persist for duration of current backend
|
||||||
closed
|
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
|
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
|
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
|
query
|
||||||
------------
|
------------
|
||||||
dblink(text,text) RETURNS setof record
|
dblink(text,text) RETURNS setof record
|
||||||
- returns a set of results from remote SELECT query
|
- returns a set of results from remote SELECT query; the first argument
|
||||||
(Note: comment out in dblink.sql to use deprecated version)
|
is either a connection string, or the name of an already opened
|
||||||
|
persistant connection
|
||||||
dblink(text) RETURNS setof record
|
dblink(text) RETURNS setof record
|
||||||
- returns a set of results from remote SELECT query, using connection
|
- returns a set of results from remote SELECT query, using the unnamed
|
||||||
already opened with dblink_connect()
|
connection already opened with dblink_connect()
|
||||||
|
|
||||||
execute
|
execute
|
||||||
------------
|
------------
|
||||||
dblink_exec(text, text) RETURNS text
|
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
|
dblink_exec(text) RETURNS text
|
||||||
- executes an INSERT/UPDATE/DELETE query remotely, using connection
|
- executes an INSERT/UPDATE/DELETE query remotely, using connection
|
||||||
already opened with dblink_connect()
|
already opened with dblink_connect()
|
||||||
@ -136,19 +157,6 @@ Installation:
|
|||||||
- builds an update statement using a local tuple, replacing the
|
- builds an update statement using a local tuple, replacing the
|
||||||
selection key field values with alternate supplied values
|
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:
|
Documentation:
|
||||||
|
|
||||||
Note: Parameters representing relation names must include double
|
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
|
* Functions returning results from a remote database
|
||||||
*
|
*
|
||||||
* Joe Conway <mail@joeconway.com>
|
* 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;
|
* ALL RIGHTS RESERVED;
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software and its
|
* Permission to use, copy, modify, and distribute this software and its
|
||||||
@ -30,36 +33,9 @@
|
|||||||
#ifndef DBLINK_H
|
#ifndef DBLINK_H
|
||||||
#define 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
|
* 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_connect(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_disconnect(PG_FUNCTION_ARGS);
|
extern Datum dblink_disconnect(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_open(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_record(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_exec(PG_FUNCTION_ARGS);
|
extern Datum dblink_exec(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_get_pkey(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_insert(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_build_sql_delete(PG_FUNCTION_ARGS);
|
extern Datum dblink_build_sql_delete(PG_FUNCTION_ARGS);
|
||||||
extern Datum dblink_build_sql_update(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)
|
CREATE OR REPLACE FUNCTION dblink_connect (text)
|
||||||
RETURNS text
|
RETURNS text
|
||||||
AS 'MODULE_PATHNAME','dblink_connect'
|
AS 'MODULE_PATHNAME','dblink_connect'
|
||||||
LANGUAGE 'C' WITH (isstrict);
|
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 ()
|
CREATE OR REPLACE FUNCTION dblink_disconnect ()
|
||||||
RETURNS text
|
RETURNS text
|
||||||
AS 'MODULE_PATHNAME','dblink_disconnect'
|
AS 'MODULE_PATHNAME','dblink_disconnect'
|
||||||
LANGUAGE 'C' WITH (isstrict);
|
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)
|
CREATE OR REPLACE FUNCTION dblink_open (text,text)
|
||||||
RETURNS text
|
RETURNS text
|
||||||
AS 'MODULE_PATHNAME','dblink_open'
|
AS 'MODULE_PATHNAME','dblink_open'
|
||||||
LANGUAGE 'C' WITH (isstrict);
|
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)
|
CREATE OR REPLACE FUNCTION dblink_fetch (text,int)
|
||||||
RETURNS setof record
|
RETURNS setof record
|
||||||
AS 'MODULE_PATHNAME','dblink_fetch'
|
AS 'MODULE_PATHNAME','dblink_fetch'
|
||||||
LANGUAGE 'C' WITH (isstrict);
|
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)
|
CREATE OR REPLACE FUNCTION dblink_close (text)
|
||||||
RETURNS text
|
RETURNS text
|
||||||
AS 'MODULE_PATHNAME','dblink_close'
|
AS 'MODULE_PATHNAME','dblink_close'
|
||||||
LANGUAGE 'C' WITH (isstrict);
|
LANGUAGE 'C' WITH (isstrict);
|
||||||
|
|
||||||
-- Note: if this is not a first time install of dblink, uncomment the
|
CREATE OR REPLACE FUNCTION dblink_close (text,text)
|
||||||
-- following DROP which prepares the database for the new, non-deprecated
|
RETURNS text
|
||||||
-- version.
|
AS 'MODULE_PATHNAME','dblink_close'
|
||||||
--DROP FUNCTION dblink (text,text);
|
LANGUAGE 'C' WITH (isstrict);
|
||||||
|
|
||||||
-- Comment out the following 3 lines if the DEPRECATED functions are used.
|
|
||||||
CREATE OR REPLACE FUNCTION dblink (text,text)
|
CREATE OR REPLACE FUNCTION dblink (text,text)
|
||||||
RETURNS setof record
|
RETURNS setof record
|
||||||
AS 'MODULE_PATHNAME','dblink_record'
|
AS 'MODULE_PATHNAME','dblink_record'
|
||||||
|
@ -6,21 +6,35 @@ dblink_connect -- Opens a persistent connection to a remote database
|
|||||||
Synopsis
|
Synopsis
|
||||||
|
|
||||||
dblink_connect(text connstr)
|
dblink_connect(text connstr)
|
||||||
|
dblink_connect(text connname, text connstr)
|
||||||
|
|
||||||
Inputs
|
Inputs
|
||||||
|
|
||||||
|
connname
|
||||||
|
if 2 arguments are given, the first is used as a name for a persistent
|
||||||
|
connection
|
||||||
|
|
||||||
connstr
|
connstr
|
||||||
|
|
||||||
standard libpq format connection string,
|
standard libpq format connection string,
|
||||||
e.g. "hostaddr=127.0.0.1 port=5432 dbname=mydb user=postgres password=mypasswd"
|
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
|
Outputs
|
||||||
|
|
||||||
Returns status = "OK"
|
Returns status = "OK"
|
||||||
|
|
||||||
Example usage
|
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
|
dblink_connect
|
||||||
----------------
|
----------------
|
||||||
OK
|
OK
|
||||||
@ -29,15 +43,18 @@ test=# select dblink_connect('dbname=template1');
|
|||||||
==================================================================
|
==================================================================
|
||||||
Name
|
Name
|
||||||
|
|
||||||
dblink_disconnect -- Closes the persistent connection to a remote database
|
dblink_disconnect -- Closes a persistent connection to a remote database
|
||||||
|
|
||||||
Synopsis
|
Synopsis
|
||||||
|
|
||||||
dblink_disconnect()
|
dblink_disconnect()
|
||||||
|
dblink_disconnect(text connname)
|
||||||
|
|
||||||
Inputs
|
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
|
Outputs
|
||||||
|
|
||||||
@ -51,3 +68,8 @@ test=# select dblink_disconnect();
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(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
|
Synopsis
|
||||||
|
|
||||||
dblink_open(text cursorname, text sql)
|
dblink_open(text cursorname, text sql)
|
||||||
|
dblink_open(text connname, text cursorname, text sql)
|
||||||
|
|
||||||
Inputs
|
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
|
cursorname
|
||||||
|
|
||||||
a reference name for the cursor
|
a reference name for the cursor
|
||||||
@ -52,9 +57,14 @@ dblink_fetch -- Returns a set from an open cursor on a remote database
|
|||||||
Synopsis
|
Synopsis
|
||||||
|
|
||||||
dblink_fetch(text cursorname, int32 howmany)
|
dblink_fetch(text cursorname, int32 howmany)
|
||||||
|
dblink_fetch(text connname, text cursorname, int32 howmany)
|
||||||
|
|
||||||
Inputs
|
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
|
cursorname
|
||||||
|
|
||||||
The reference name for the cursor
|
The reference name for the cursor
|
||||||
@ -123,9 +133,14 @@ dblink_close -- Closes a cursor on a remote database
|
|||||||
Synopsis
|
Synopsis
|
||||||
|
|
||||||
dblink_close(text cursorname)
|
dblink_close(text cursorname)
|
||||||
|
dblink_close(text connname, text cursorname)
|
||||||
|
|
||||||
Inputs
|
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
|
cursorname
|
||||||
|
|
||||||
a reference name for the cursor
|
a reference name for the cursor
|
||||||
@ -135,7 +150,8 @@ Outputs
|
|||||||
Returns status = "OK"
|
Returns status = "OK"
|
||||||
|
|
||||||
Note
|
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
|
Example usage
|
||||||
|
|
||||||
@ -157,3 +173,20 @@ test=# select dblink_close('foo');
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(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
|
Synopsis
|
||||||
|
|
||||||
dblink_exec(text connstr, text sql)
|
dblink_exec(text connstr, text sql)
|
||||||
- or -
|
dblink_exec(text connname, text sql)
|
||||||
dblink_exec(text sql)
|
dblink_exec(text sql)
|
||||||
|
|
||||||
Inputs
|
Inputs
|
||||||
|
|
||||||
|
connname
|
||||||
connstr
|
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,
|
If only one argument is used, then the unnamed connection is used.
|
||||||
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.
|
|
||||||
|
|
||||||
sql
|
sql
|
||||||
|
|
||||||
sql statement that you wish to execute on the remote host, e.g.:
|
sql statement that you wish to execute on the remote host, e.g.:
|
||||||
|
|
||||||
insert into foo values(0,'a','{"a0","b0","c0"}');
|
insert into foo values(0,'a','{"a0","b0","c0"}');
|
||||||
|
|
||||||
Outputs
|
Outputs
|
||||||
@ -36,14 +37,26 @@ Notes
|
|||||||
|
|
||||||
Example usage
|
Example usage
|
||||||
|
|
||||||
test=# select dblink_connect('dbname=dblink_test_slave');
|
select dblink_connect('dbname=dblink_test_slave');
|
||||||
dblink_connect
|
dblink_connect
|
||||||
----------------
|
----------------
|
||||||
OK
|
OK
|
||||||
(1 row)
|
(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
|
dblink_exec
|
||||||
-----------------
|
-----------------
|
||||||
INSERT 943366 1
|
INSERT 943366 1
|
||||||
(1 row)
|
(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
|
Synopsis
|
||||||
|
|
||||||
dblink(text connstr, text sql)
|
dblink(text connstr, text sql)
|
||||||
- or -
|
dblink(text connname, text sql)
|
||||||
dblink(text sql)
|
dblink(text sql)
|
||||||
|
|
||||||
Inputs
|
Inputs
|
||||||
|
|
||||||
|
connname
|
||||||
connstr
|
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,
|
If only one argument is used, then the unnamed connection is used.
|
||||||
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.
|
|
||||||
|
|
||||||
sql
|
sql
|
||||||
|
|
||||||
@ -29,7 +31,7 @@ Outputs
|
|||||||
|
|
||||||
Example usage
|
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%';
|
as t1(proname name, prosrc text) where proname like 'bytea%';
|
||||||
proname | prosrc
|
proname | prosrc
|
||||||
------------+------------
|
------------+------------
|
||||||
@ -47,13 +49,13 @@ test=# select * from dblink('dbname=template1','select proname, prosrc from pg_p
|
|||||||
byteaout | byteaout
|
byteaout | byteaout
|
||||||
(12 rows)
|
(12 rows)
|
||||||
|
|
||||||
test=# select dblink_connect('dbname=template1');
|
select dblink_connect('dbname=template1');
|
||||||
dblink_connect
|
dblink_connect
|
||||||
----------------
|
----------------
|
||||||
OK
|
OK
|
||||||
(1 row)
|
(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%';
|
as t1(proname name, prosrc text) where proname like 'bytea%';
|
||||||
proname | prosrc
|
proname | prosrc
|
||||||
------------+------------
|
------------+------------
|
||||||
@ -71,6 +73,33 @@ test=# select * from dblink('select proname, prosrc from pg_proc')
|
|||||||
byteaout | byteaout
|
byteaout | byteaout
|
||||||
(12 rows)
|
(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:
|
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}
|
9 | j | {a9,b9,c9}
|
||||||
(2 rows)
|
(2 rows)
|
||||||
|
|
||||||
-- should generate "no connection available" error
|
-- should generate "connection not available" error
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||||
WHERE t.a > 7;
|
WHERE t.a > 7;
|
||||||
ERROR: dblink: no connection available
|
ERROR: dblink_record: connection not available
|
||||||
-- create a persistent connection
|
-- create a persistent connection
|
||||||
SELECT dblink_connect('dbname=regression');
|
SELECT dblink_connect('dbname=regression');
|
||||||
dblink_connect
|
dblink_connect
|
||||||
@ -172,10 +172,10 @@ SELECT dblink_close('rmt_foo_cursor');
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- should generate "cursor rmt_foo_cursor does not exist" error
|
-- should generate "cursor not found: rmt_foo_cursor" error
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
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
|
-- close the persistent connection
|
||||||
SELECT dblink_disconnect();
|
SELECT dblink_disconnect();
|
||||||
dblink_disconnect
|
dblink_disconnect
|
||||||
@ -183,11 +183,12 @@ SELECT dblink_disconnect();
|
|||||||
OK
|
OK
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
-- should generate "no connection available" error
|
-- should generate "no connection to the server" error
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||||
WHERE t.a > 7;
|
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
|
-- 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
|
-- 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);
|
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
|
OK
|
||||||
(1 row)
|
(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[])
|
FROM dblink('dbname=regression','SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||||
WHERE t.a > 7;
|
WHERE t.a > 7;
|
||||||
|
|
||||||
-- should generate "no connection available" error
|
-- should generate "connection not available" error
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||||
WHERE t.a > 7;
|
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
|
-- close the cursor
|
||||||
SELECT dblink_close('rmt_foo_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 *
|
SELECT *
|
||||||
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
FROM dblink_fetch('rmt_foo_cursor',4) AS t(a int, b text, c text[]);
|
||||||
|
|
||||||
-- close the persistent connection
|
-- close the persistent connection
|
||||||
SELECT dblink_disconnect();
|
SELECT dblink_disconnect();
|
||||||
|
|
||||||
-- should generate "no connection available" error
|
-- should generate "no connection to the server" error
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
FROM dblink('SELECT * FROM foo') AS t(a int, b text, c text[])
|
||||||
WHERE t.a > 7;
|
WHERE t.a > 7;
|
||||||
@ -143,3 +143,98 @@ WHERE a = 11;
|
|||||||
|
|
||||||
-- close the persistent connection
|
-- close the persistent connection
|
||||||
SELECT dblink_disconnect();
|
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