pgsql 使用 COALESCE()
函数时(使用Navicat查询工具),出现这个问题,中文意思应该是:“COALESCE类型不能匹配文本和整数”。
问题语句差不多是这样的 …… COALESCE('1',0)::int ……
,然而当我直接使用这个语句进行测试,是没有问题的(如下);但是如果内嵌到长的SQL语句里面就会报这个错误,很奇怪,不知道是查询工具的问题,还是函数自身问题(后续我又用pgadmin进行了测试,发现)。
select null::int;
select '1'::int;
select COALESCE(1, 0)::int;
select COALESCE('1', 0)::int;
select COALESCE(1, '0')::int;
select COALESCE('1', '0')::int;
不管咋样问题还是的解决,需要保持前后数据格式一直,我是都改成字符串了:
…… COALESCE('1','0')::int ……
Navicat查询
报错信息(比较详细)
ERROR: COALESCE types text and integer cannot be matched
LINE 14: , COALESCE(dsrTemp.dsrcount, 0) as ppaccount
^
时间: 0.075s
pgadmin
报错信息
ERROR: COALESCE types text and integer cannot be matched
LINE 14: , COALESCE(dsrTemp.dsrcount, 0) as ppaccount
^
SQL 状态: 42804
字符: 614
查看对应文档可以找到该状态码:
- https://www.postgresql.org/search/?u=%2Fdocs%2F10%2F&q=42804
- http://shouce.jb51.net/postgresql/errcodes-appendix.htm