postgresql 无法确定 python-pgsql 中参数 $1 的数据类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12170842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
could not determine data type of parameter $1 in python-pgsql
提问by Abhijeet Rastogi
I have a simple table (named test) as:
我有一个简单的表(名为 test):
id | integer
name | character varying(100)
intval | integer
When I try to use prepare statement to update the name like this in python. (I am using python-pgsql http://pypi.python.org/pypi/python-pgsql/)
当我尝试使用 prepare 语句在 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 = '' where name = ''"
>>> 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
The demo file for the module can be seen at http://sprunge.us/VgLY?python.
该模块的演示文件可以在http://sprunge.us/VgLY?python上看到。
回答by notbad.jpeg
I'm guessing that it could be your single quotes around $1
and $2
inside your string. In the main changes from PYGresql it says that:
我猜它可能是您的字符串周围$1
和$2
内部的单引号。在 PYGresql 的主要变化中,它说:
- support for bind parameters, alleviating the need for extensive, expensive and vulnerable quoting of user-supplied data
- 支持绑定参数,减少对用户提供的数据进行大量、昂贵和易受攻击的引用的需要
So I'm assuming the single quotes are overloading the string with too many quotes, or just breaking the parser in python-pgsql.
所以我假设单引号用太多引号重载了字符串,或者只是破坏了 python-pgsql 中的解析器。
回答by Kartikey Kumar Srivastava
Dont add single quotes with $1 and $2 .... It might be leading to unrecognition of type...
不要用 $1 和 $2 添加单引号......这可能会导致无法识别类型......