[英]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.