dblink_open
dblink_open — открывает курсор в удалённой базе данных
Синтаксис
dblink_open(text cursorname, text sql [, bool fail_on_error]) returns text dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) returns text
Описание
Функция dblink_open()
открывает курсор в удалённой базе данных. Открытым курсором можно будет манипулировать функциями dblink_fetch()
и dblink_close()
.
Аргументы
connname
Имя используемого подключения; опустите этот параметр, чтобы использовать безымянное подключение.
cursorname
Имя, назначаемое курсору.
sql
Оператор
SELECT
, который вы хотите выполнять в удалённой базе данных, напримерselect * from pg_class
.fail_on_error
Если равен true (это значение по умолчанию), в случае ошибки, выданной на удалённой стороне соединения, ошибка также выдаётся локально. Если равен false, удалённая ошибка выдаётся локально как ЗАМЕЧАНИЕ, и возвращаемым значением функции будет
ERROR
.
Возвращаемое значение
Возвращает состояние, OK
или ERROR
.
Замечания
Так как курсор может существовать только в рамках транзакции, функция dblink_open
начинает явный блок транзакции (командой BEGIN
) на удалённой стороне, если транзакция там ещё не открыта. Эта транзакция будет снова закрыта при соответствующем вызове dblink_close
. Заметьте, что если вы с помощью dblink_exec
изменяете данные между вызовами dblink_open
и dblink_close
, а затем происходит ошибка, либо если вы вызываете dblink_disconnect
перед dblink_close
, ваши изменения будут потеряны, так как транзакция будет прервана.
Примеры
SELECT dblink_connect('dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) SELECT dblink_open('foo', 'select proname, prosrc from pg_proc'); dblink_open ------------- OK (1 row)
dblink_open
dblink_open — opens a cursor in a remote database
Synopsis
dblink_open(text cursorname, text sql [, bool fail_on_error]) returns text dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) returns text
Description
dblink_open()
opens a cursor in a remote database. The cursor can subsequently be manipulated with dblink_fetch()
and dblink_close()
.
Arguments
connname
Name of the connection to use; omit this parameter to use the unnamed connection.
cursorname
The name to assign to this cursor.
sql
The
SELECT
statement that you wish to execute in the remote database, for exampleselect * from pg_class
.fail_on_error
If true (the default when omitted) 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 reported as a NOTICE, and the function's return value is set to
ERROR
.
Return Value
Returns status, either OK
or ERROR
.
Notes
Since a cursor can only persist within a transaction, dblink_open
starts an explicit transaction block (BEGIN
) on the remote side, if the remote side was not already within a transaction. This transaction will be closed again when the matching dblink_close
is executed. Note that if you use dblink_exec
to change data between dblink_open
and dblink_close
, and then an error occurs or you use dblink_disconnect
before dblink_close
, your change will be lost because the transaction will be aborted.
Examples
SELECT dblink_connect('dbname=postgres options=-csearch_path='); dblink_connect ---------------- OK (1 row) SELECT dblink_open('foo', 'select proname, prosrc from pg_proc'); dblink_open ------------- OK (1 row)