Python警告:截断了错误的DOUBLE值

编程入门 行业动态 更新时间:2024-10-24 15:13:30
本文介绍了Python警告:截断了错误的DOUBLE值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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值

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

发布评论

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

>www.elefans.com

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