我有一个简单的表(名为 test):
id | integer
name | character varying(100)
intval | integer
当我尝试使用准备语句在 python 中更新这样的名称时。(我正在使用 python-pgsql http://pypi.python.org/pypi/python-pgsql/)
>>> for i in db.execute("select * from test"): print i
...
(1, 'FOO', None)
>>> query = "UPDATE test set name = '$1' where name = '$2'"
>>> cu.execute(query, "myname", "FOO")
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/pgsql.py", line 119, in execute
ret = self._source.execute(operation, params)
ProgrammingError: ERROR: could not determine data type of parameter $1
该模块的演示文件可以在http://sprunge.us/VgLY?python看到。