【问题标题】:Python Dataset module error: You might need to add explicit type castsPython 数据集模块错误:您可能需要添加显式类型转换
【发布时间】:2015-08-05 10:02:09
【问题描述】:

使用 python 数据集模块从 postgres db 查询数据有一些困难,我的数据是 varchar 类型,当我查询数据时收到以下错误。

错误:

第 1 行:...t * from sources.product where post = 31055183...

提示:没有运算符匹配给定的名称和参数类型。您可能需要添加显式类型转换。 [SQL: 'select * from sources.product where post = 310551835']

使用的代码片段:

deltas = db.query('select * from deltas.deltas_del')

for idx in deltas:
            print type(idx['post'])
            prod = db.query('select * from sources.product where post = 310551835')

【问题讨论】:

  • 您是否尝试将值 310551835 放在引号中,因为产品应该是 varchar?
  • @jlyoung 对,是的,我确实尝试过,但返回了同样的错误。
  • 你确定你的 where 子句是正确的吗?您的错误消息显示“post”,但您发布的代码的 sn-p 显示“post_full”。试试:prod = db.query("select * from sources.product where post = '310551835'")
  • @jlyoung 正确,这是 where 子句中引号“”的问题
  • 酷。我会把它写成答案,如果有帮助,你可以接受答案。

标签: python sqlalchemy dataset psycopg2


【解决方案1】:

将引号添加到 where 子句右侧的值,因为您正在使用 varchar 进行过滤。

prod = db.query("select * from sources.product where post = '310551835'"

【讨论】:

    猜你喜欢
    • 2017-06-28
    • 2015-04-07
    • 2019-05-27
    • 2020-06-16
    • 2013-09-09
    • 2018-11-08
    • 2017-07-16
    • 2017-08-31
    • 1970-01-01
    相关资源
    最近更新 更多