Mar*_* C. 3 sql where-clause snowflake-cloud-data-platform sql-null
在 Snowflake 中,条件表达式x = NULL和x IS NULL条件表达式有什么区别?x IS NULL当我想找到某些列是空白的行时,这似乎是我想要的。我问,因为x = NULL被视为有效的语法,我很好奇这个表达式是否有不同的应用程序。
x = NULL 和 x IS NULL 有什么区别
在 Snowflake 中,就像在其他 RDBMS 中一样,Nothing 等于NULL(甚至NULL它自己),因此条件x = NULL(这是有效的 SQL 语法)将始终评估为 false(实际上,它NULL在大多数 RDBMS 中评估为,这不是真的)。请注意,对于非相等比较也是如此:这NULL <> NULL也是错误的。
检查变量是否的典型方法NULL是使用x IS NULL构造,如果x是,则评估为真NULL。你也可以使用x IS NOT NULL。此语法是为 保留的NULL,因此类似于x IS y语法错误。
这是一个小演示:
select
case when 1 = null then 1 else 0 end 1_equal_null,
case when 1 <> null then 1 else 0 end 1_not_equal_null,
case when null is null then 1 else 0 end null_is_null,
case when 1 is not null then 1 else 0 end 1_is_not_null
Run Code Online (Sandbox Code Playgroud)
1_equal_null | 1_not_equal_null | null_is_null | 1_is_not_null
-----------: | ---------------: | -----------: | ------------:
0 | 0 | 1 | 1