繁体   English   中英

基于postgres数据库的数字=字符变化:运算符不存在

[英]Numeric=character varying :operator does not exist based on postgres database

我有这样的查询:

Select office_name, ofc_code 
from table1 
where ofc_code in (select ofc_institution from table2 where id ='2')

如果我运行这个,我得到一个错误:

Operator does not exist:numeric = character varying
Hint : no operator matches the given name and argument types

在上面的查询中: ofc_code是数字, ofc_institution是字符变化

不要将苹果与桔子相提并论。 '2'是字符串值, 2是数字。

如果您确定ofc_institution仅包含数字,则还需要将其转换为数字(然后的问题是:到底为什么要将数字存储在varchar列中?):

Select office_name, ofc_code 
from table1 
where ofc_code in (select ofc_institution::numeric
                   from table2 
                   where id = 2);

如果不能确定ofc_institution始终是数字,则将ofc_code转换为字符串-但这引出了一个问题,为什么要比较这些列以开头:

Select office_name, ofc_code 
from table1 
where ofc_code::varchar in (select ofc_institution
                            from table2 
                            where id = 2);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM