PostgreSQL dblink_open

2021-09-16 15:39 更新

dblink_open — 在一個遠(yuǎn)程數(shù)據(jù)庫中打開一個游標(biāo)

大綱

dblink_open(text cursorname, text sql [, bool fail_on_error]) 返回 text
dblink_open(text connname, text cursorname, text sql [, bool fail_on_error]) 返回 text

描述

dblink_open()在一個遠(yuǎn)程數(shù)據(jù)庫中打開一個游標(biāo)。該游標(biāo)能夠隨后使用dblink_fetch()dblink_close()進(jìn)行操縱。

參數(shù)

connname

要使用的連接名。忽略這個參數(shù)將使用未命名連接。

cursorname

要賦予給這個游標(biāo)的名稱。

sql

你希望在遠(yuǎn)程數(shù)據(jù)庫中執(zhí)行的SELECT語句,例如select * from pg_class。

fail_on_error

如果為真(忽略時的默認(rèn)值),那么在連接的遠(yuǎn)端拋出的一個錯誤也會導(dǎo)致本地拋出一個錯誤。如果為假,遠(yuǎn)程錯誤只在本地被報告為一個 NOTICE,并且該函數(shù)的返回值被設(shè)置為ERROR。

返回值

返回狀態(tài),OK或者ERROR。

注解

因?yàn)橐粋€游標(biāo)只能在一個事務(wù)中持續(xù),如果遠(yuǎn)端還沒有在一個事務(wù)中,dblink_open會在遠(yuǎn)端開始一個顯式事務(wù)塊(BEGIN)。當(dāng)匹配的dblink_close被執(zhí)行時,這個事務(wù)將再次被關(guān)閉。注意如果你使用dblink_execdblink_opendblink_close之間改變數(shù)據(jù),并且接著發(fā)生了一個錯誤或者你在dblink_close之前使用了dblink_disconnect,你的更改將被丟失,因?yàn)槭聞?wù)將被中止。

例子

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)
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號