我正在尝试使用mysql-python从"foo"表中获取"bar_ids".为此,我收到以下错误,并且仅收到几个bar_id.如何正确获得此信息而不会出现警告错误?
I am trying to fetch "bar_ids" from "foo" table using mysql-python. To this end, I got the following error and I am receiving only few bar_ids. How do I get this correctly without warning error?
我的表格如下所示:
create table foo (foo_id int, bar_id int, foo_name varchar(255))我的查询&错误:
My query & Error:
foo_ids = 16600, 16602, 16607, 16609, 16611, 16613警告:第1行的"bar_id"列的数据被截断了
Warning: Data truncated for column 'bar_id' at row 1
cursor.execute("""select bar_id from foo where foo_id in (%s)""", (foo_ids,))警告:错误的DOUBLE值被截断了:"16600、16602、16607、16609、16611、16613"
Warning: Truncated incorrect DOUBLE value: '16600, 16602, 16607, 16609, 16611, 16613'
cursor.execute("""select bar_id from foo where foo_id in (%s)""", (foo_ids,))推荐答案
在SO中曾有人问过这个问题.放入响应,这样可能有助于给出一些背景信息,并帮助@brisk继续阅读此类错误.
This question has been asked before in SO. Putting in a response so it might help to give some context and help @brisk read this sort of error going forward.
问题在于它将'foo_ids'作为字符串而不是单个值.因此,它实际上是在尝试运行:
The problem is that it is taking 'foo_ids' as a string and not as individual values. So it's essentially trying to run:
select bar_id from foo where foo_id in ('16600, 16602, 16607, 16609, 16611, 16613')注意报价吗?您希望它运行:
Notice the quotes? You want it to run:
select bar_id from foo where foo_id in (16600, 16602, 16607, 16609, 16611, 16613)因此,当您报告错误时,它会在数字周围包含引号".
so when you reported your error, it included 'quotes' around the numbers.
有很少 解决方案.
更多推荐
Python警告:截断了错误的DOUBLE值
发布评论