我有这个:COALESCE(amount ,0) as amount
。amount
的数据类型是numeric
。
而不是0
我想要N/A
。我该怎么做?我有错误:
ERROR: invalid input syntax for type numeric: "N/A"
最佳答案
在您的情况下,更适合此代码: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
关于postgresql - 如何在PostgreSQL中将int转换为字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51479240/