我有这个:COALESCE(amount ,0) as amount
。 amount
的数据类型为numeric
。
我想要0
而不是N/A
。我怎样才能做到这一点?我遇到错误:
ERROR: invalid input syntax for type numeric: "N/A"
答案 0 :(得分:1)
使用类型转换:
coalesce(CAST(amount AS text), 'N/A')
答案 1 :(得分:0)
您更适合以下代码:coalesce(cast(nullif(amount, 0) as text), 'N/A')
有关保存的其他信息:
case
when coalesce(cast(nullif(a.amount1, 0) as text), 'N/A') = 'N/A' then 'N/A'
when coalesce(cast(nullif(a.amount2, 0) as text), 'N/A') = 'N/A' then 'N/A'
else (coalesce(cast(nullif(a.amount1 - a.amount2, 0) as text), 'N/A'))
end as savings