无法确定python

编程入门 行业动态 更新时间:2024-10-27 21:14:43
无法确定python-pgsql中参数$ 1的数据类型(could not determine data type of parameter $1 in python-pgsql)

我有一个简单的表(名为test):

id | integer name | character varying(100) intval | integer

当我尝试使用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 = '$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上看到该模块的演示文件。

I have a simple table (named test) as:

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/)

>>> 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

The demo file for the module can be seen at http://sprunge.us/VgLY?python.

最满意答案

我猜你的字符串里面的单引号可能是$1和$2 。 在PYGresql的主要变化中它说:

支持绑定参数,减少了对用户提供的数据的广泛,昂贵和易受攻击的引用的需要

所以我假设单引号用过多的引号重载字符串,或者只是破坏了python-pgsql中的解析器。

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:

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.

更多推荐

本文发布于:2023-07-24 20:53:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1250978.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!