You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Snowflake中使用'is'筛选布尔列报错,如何正确查询?

布尔列查询语法报错的解决方法

问题场景

执行以下查询时出现语法错误:

select * from table_name where active is true

语法错误:意外的 'is'。

但执行判断列非空的语句却能正常返回结果:

select * from table_name where active is not null

其中active列的数据类型为布尔型。

问题原因

不同SQL数据库的语法兼容度存在差异,部分数据库不支持is true这种语法来判断布尔列的真值。而is not null属于SQL标准语法,几乎所有数据库都支持,因此可以正常执行。

可行解决方案

针对布尔列active,可以替换为以下几种兼容写法:

  • 直接引用列名(多数支持布尔类型的数据库通用):
    select * from table_name where active
    
  • 使用等于判断:
    select * from table_name where active = true
    
  • 若数据库将布尔值以数值形式存储(如1代表真、0代表假),可使用数值匹配:
    select * from table_name where active = 1
    

内容的提问来源于stack exchange,提问作者Erik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 07:18:11