PostgreSQL boolean cast(0为false)

前端之家收集整理的这篇文章主要介绍了PostgreSQL boolean cast(0为false)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我更喜欢1/0而不是t / f,所以在将布尔值转换为整数时应该使用什么?
select coalesce((null::boolean)::int,0)

要么

select case null::boolean when 't' then 1 else 0 end

……别的什么?

无论你做什么,布尔值null都不等于false,只要数字null等于零.

尝试:

Cast(col1 as integer)

如果你真的想将null视为false,那么:

case when col1 then 1 else 0 end

但这将是一件坏事

猜你在找的Postgre SQL相关文章