我有这个:COALESCE(amount ,0) as amount。的数据类型amount是numeric.
而不是0我想要的N/A。我怎样才能做到这一点?我收到错误:
ERROR: invalid input syntax for type numeric: "N/A"
Run Code Online (Sandbox Code Playgroud)
在你的情况下更适合这个代码: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
Run Code Online (Sandbox Code Playgroud)