dblink_open
Name
dblink_open -- 打开远程数据库中的游标
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
描述
dblink_open()打开了远程数据库中的游标。 游标可以随后使用dblink_fetch()和dblink_close() 被操作。
参数
conname
要使用的连接名称;省略这个参数使用未命名连接。
cursorname
分配给这个游标的名称。
sql
你希望在远程数据库中执行的SELECT语句,比如select * from pg_class。
fail_on_error
如果真(忽略时缺省)那么在连接的远程端抛出的错误也会导致本地抛出错误, 如果假,那么远程错误在本地作为NOTICE被报告, 并且函数的返回值设置为ERROR。
返回值
返回状态,OK或者ERROR。
注意
因为游标只能停留在事务块中,如果远程端已经不在事务中, 那么dblink_open在远程端开始显式事务块(BEGIN), 当执行匹配的dblink_close时,则该事务将再次被关闭。 注意如果在dblink_open和dblink_close之间使用 dblink_exec改变数据,那么会产生错误或者你在dblink_close之前使用 dblink_disconnect,你的改变将丢失,因为终止了事务。
例子
SELECT dblink_connect('dbname=postgres');
dblink_connect
----------------
OK
(1 row)
SELECT dblink_open('foo', 'select proname, prosrc from pg_proc');
dblink_open
-------------
OK
(1 row)