PostgreSQL 布尔比较
PostgreSQL boolean comparison
下面对比有区别吗
#1
where x = true
#2
where x is true
#3
where x = '1'
#4
where x
使用is
或is not
将处理值为空的情况。如果依赖=
,比较的结果也会是null
select null is true as "is", null = true as "equal";
is | equal
----+-------
f |
(1 row)
这与
完全一样
WHERE x
TRUE
、FALSE
或 NULL
正好是 x
。
这与第一种情况相同,除了当x
为NULL时,在这种情况下它将是FALSE
。所以和
一样
WHERE coalesce(x, FALSE)
这恰好与第一种情况相同,因为'1'
被解释为TRUE
。见 the documentation:
The datatype input function for type boolean
accepts these string representations for the “true” state:
true
yes
on
1
我喜欢的方法是最简单的:
WHERE x
下面对比有区别吗
#1
where x = true
#2
where x is true
#3
where x = '1'
#4
where x
使用is
或is not
将处理值为空的情况。如果依赖=
,比较的结果也会是null
select null is true as "is", null = true as "equal";
is | equal
----+-------
f |
(1 row)
这与
完全一样WHERE x
TRUE
、FALSE
或NULL
正好是x
。这与第一种情况相同,除了当
一样x
为NULL时,在这种情况下它将是FALSE
。所以和WHERE coalesce(x, FALSE)
这恰好与第一种情况相同,因为
'1'
被解释为TRUE
。见 the documentation:The datatype input function for type
boolean
accepts these string representations for the “true” state:true
yes
on
1
我喜欢的方法是最简单的:
WHERE x