postgresql处理字段数据为空转为0的方法

COALESCE(a.floor_num, 0) as floor_num

此函数是有用的,但是使用报错,结果如下

postgresql处理字段数据为空转为0的方法

检查后发现时字段类型转义错误,floor_num是varchar类型,需要加上引号

COALESCE(a.floor_num, ‘0’) as floor_num

postgresql处理字段数据为空转为0的方法

执行正确。