PyPgSQL

来自开放百科 - 灰狐
跳转到: 导航, 搜索

pyPgSQL is a package of two modules that provide a Python DB-API 2.0 compliant interface to PostgreSQL databases. The first module, libpq, exports the PostgreSQL C API to Python. This module is written in C and can be compiled into Python or can be dynamically loaded on demand. The second module, PgSQL, provides the DB-API 2.0 compliant interface and support for various PostgreSQL data types, such as INT8, NUMERIC, MONEY, BOOL, ARRAYS, etc. This module is written in Python.

http://pypgsql.sourceforge.net/

Debian

#apt-get install python2.3-pgsql
su postgres
createdb test
python
>>> from pyPgSQL import PgSQL
>>> cx = PgSQL.connect(database="test", client_encoding="utf-8", unicode_results=1)
>>> cu = cx.cursor()
>>> cu.execute("set client_encoding to unicode")
>>> cu.execute("insert into test(v) values (%s)", (u'\x99sterreich',))
>>> cu.execute("select v from test")
>>> cu.fetchone()
[u'\x99sterreich']
>>>
分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱