次のような単純なテーブル(testという名前)があります。
id | integer
name | character varying(100)
intval | integer
pythonでこのような名前を更新するためにprepareステートメントを使用しようとすると。(私は 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で見ることができます。