postgresql Postgres:错误:运算符不存在:字符变化 = bigint

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34740652/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:08:36  来源:igfitidea点击:

Postgres: ERROR: operator does not exist: character varying = bigint

postgresql

提问by Athanasia Ntalla

My query is something like this. I try to get a status for a list of ids.

我的查询是这样的。我尝试获取 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)

I get an error though that says:

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

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.

Do you have any clue on how I should reform the ids to get it work? Thanks a lot!

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

回答by a_horse_with_no_name

Your order_numberis a varchar, you can't compare that to a number (123is a number in SQL, '123'is a string constant)

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

You need to use string literals:

您需要使用字符串文字:

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

More details in the manual:
http://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS

手册中的更多详细信息:http:
//www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS