在AWS RedShift中,boolean_column = true
和boolean_column IS true
有区别吗?
doctor 建议"始终显式判断布尔值"https://docs.aws.amazon.com/redshift/latest/dg/r_Boolean_type.html
我有一个带有三个布尔列的红移表.以下查询运行时没有错误,并返回预期结果(即,如果三列中的任何一列为真,则my_any_column
为true
):
-- Does work
SELECT
(
boolean_column_01 = true
OR boolean_column_02 = true
OR boolean_column_03 = true
) AS my_any_column
FROM
my_example_table;
但是,如果我按如下方式更改查询,则会出现错误:
-- Does not work
SELECT
(
boolean_column_01 is true
OR boolean_column_02 is true
OR boolean_column_03 is true
) AS my_any_column
FROM
my_example_table;
以下是使用is
的查询的错误消息:
SQL Error [XX000]: ERROR: Assert
Detail:
-----------------------------------------------
error: Assert
code: 1000
context: arg_func_info.is_nullable_ == fld->a_nullable() - arg_func_info.is_nullable_=0, fld->a_nullable()=1.
query: 1008428
location: cg_expr_fn_builder.cpp:8993
process: padbmaster [pid=4919]
-----------------------------------------------
最奇怪的是,下面的查询没有错误地运行:
-- Does work
SELECT
(
boolean_column_01 is true
OR boolean_column_02 is true
OR boolean_column_03 = true
) AS my_any_column
FROM
my_example_table;
对于2*is
和1*=
,查询有效(与顺序无关),但一旦有3*is
,它就会失败.
作为一种解决办法,我可以始终使用=
而不是is
,但我在文档中找不到这样的建议.