【问题标题】:Postgres: ERROR: operator does not exist: character varying = bigintPostgres:错误:运算符不存在:字符变化 = bigint
【发布时间】:2016-04-16 21:22:13
【问题描述】:

我的查询是这样的。我尝试获取 id 列表的状态。

select order_number, order_status_name
from data.order_fact s
join data.order_status_dim l
on s.order_status_key = l.order_status_key
where 
order_number in (1512011196169,1512011760019,1512011898493,1512011972111)

我得到一个错误,虽然它说:

ERROR:  operator does not exist: character varying = bigint
LINE 6: order_number in (1512011196169,1512011760019,1512011898493,1...
                     ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.

您对我应该如何修改 ID 以使其正常工作有任何线索吗? 非常感谢!

【问题讨论】:

    标签: postgresql


    【解决方案1】:

    您的 order_number 是一个 varchar,您不能将其与数字进行比较(123 是 SQL 中的数字,'123' 是字符串常量)

    你需要使用字符串字面量:

    order_number in ('1512011196169','1512011760019','1512011898493','1512011972111')
    

    更多详情见手册:
    http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS

    【讨论】:

      【解决方案2】:

      如果您无法更改in 中的数字类型,您可以使用cast

      select * from numbers_as_string
      where cast(my_numbers_as_string as int) in (1,2,3)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-12-09
        • 2021-11-12
        • 1970-01-01
        • 2012-07-02
        • 2021-05-02
        • 2018-05-05
        • 2019-07-03
        • 2012-05-19
        相关资源
        最近更新 更多