使用Python第三方库psycopg2连接集群 使用约束 由于psycopg2是基于PostgreSQL的客户端接口,它的功能DWS并不能完全支持。具体支持情况请见下表。 说明 以下接口支持情况是基于Python 3.8.5及psycopg 2.9.1版本。 DWS对psycopg2主要接口支持情况 类名 功能描述 函数/成员变量 支持 备注 connections basic cursor(nameNone,cursorfactoryNone,scrollableNone,withholdFalse) Y connections basic commit() Y connections basic rollback() Y connections basic close() Y connections Twophase commit support methods xid(formatid,gtrid,bqual) Y connections Twophase commit support methods tpcbegin(xid ) Y connections Twophase commit support methods tpcprepare() N 内核不支持显式prepare transaction connections Twophase commit support methods tpccommit([xid ]) Y connections Twophase commit support methods tpcrollback([xid ]) Y connections Twophase commit support methods tpcrecover() Y connections Twophase commit support methods closed Y connections Twophase commit support methods cancel() Y connections Twophase commit support methods reset() N 不支持DISCARD ALL connections Twophase commit support methods dsn Y connections Transaction control methods and attributes. setsession(isolationlevelNone,readonlyNone,deferrableNone,autocommitNone) Y 数据库不支持session中设置defaulttransactionreadonly connections Transaction control methods and attributes. autocommit Y connections Transaction control methods and attributes. isolationlevel Y connections Transaction control methods and attributes. readonly N 数据库不支持session中设置defaulttransactionreadonly connections Transaction control methods and attributes. deferrable Y connections Transaction control methods and attributes. setisolationlevel(level ) Y connections Transaction control methods and attributes. encoding Y connections Transaction control methods and attributes. setclientencoding(enc) Y connections Transaction control methods and attributes. notices N 数据库不支持listen/notify connections Transaction control methods and attributes. notifies Y connections Transaction control methods and attributes. cursorfactory Y connections Transaction control methods and attributes. info Y connections Transaction control methods and attributes. status Y connections Transaction control methods and attributes. lobject N 数据库不支持大对象相关操作 connections Methods related to asynchronous support poll() Y connections fileno() Y connections isexecuting() Y connections Interoperation with other C API modules pgconnptr Y connections getnativeconnection() Y connections informative methods of the native connection gettransactionstatus() Y connections informative methods of the native connection protocolversion Y connections informative methods of the native connection serverversion Y connections informative methods of the native connection getbackendpid() Y 获取到的不是后台的pid,是逻辑连接的id号 connections informative methods of the native connection getparameterstatus(parameter) Y connections informative methods of the native connection getdsnparameters() Y cursor basic description Y cursor basic close() Y cursor basic closed Y cursor basic connection Y cursor basic name Y cursor basic scrollable N 数据库不支持SCROLL CURSOR cursor basic withhold N withhold cursor在commit前需要关闭 cursor Commands execution methods execute(query,varsNone) Y cursor Commands execution methods executemany(query,varslist) Y cursor Commands execution methods callproc(procname[,parameters]) Y cursor Commands execution methods mogrify(operation[,parameters]) Y cursor Commands execution methods setinputsizes(sizes ) Y cursor Commands execution methods fetchone() Y cursor Commands execution methods fetchmany([sizecursor.arraysize]) Y cursor Commands execution methods fetchall() Y cursor Commands execution methods scroll(value[,mode'relative']) N 数据库不支持SCROLL CURSOR cursor Commands execution methods arraysize Y cursor Commands execution methods itersize Y cursor Commands execution methods rowcount Y cursor Commands execution methods rownumber Y cursor Commands execution methods lastrowid Y cursor Commands execution methods query Y cursor Commands execution methods statusmessage Y cursor Commands execution methods cast(oid , s ) Y cursor Commands execution methods tzinfofactory Y cursor Commands execution methods nextset() Y cursor Commands execution methods setoutputsize(size [, column ]) Y cursor COPYrelated methods copyfrom(file,table,sep't',null'N',size8192,columnsNone) Y cursor COPYrelated methods copyto(file,table,sep't',null'N',columnsNone) Y cursor COPYrelated methods copyexpert(sql,file,size8192) Y cursor Interoperation with other C API modules pgresultptr Y