雪花 Where 子句未过滤?

时间:2021-04-28 04:21:09

标签: sql where-clause snowflake-cloud-data-platform

我在雪花中运行此查询:

select *
from my_database.information_schema.tables
where
    table_schema NOT LIKE '%information%';

当我查看记录时,其中一些将 INFORMATION_SCHEMA 作为 table_schema.

为什么我的过滤器不起作用?

2 个答案:

答案 0 :(得分:4)

LIKE 区分大小写,而 ILIKE 不区分大小写。你的两个字符串是不同的情况。所以我建议你换成ILIKE

SELECT 'a' LIKE 'A' as "a_like_A", 'a' ILIKE 'A' as "a_ilike_A";

给出:

a_like_A    a_ilike_A
FALSE       TRUE

答案 1 :(得分:0)

<块引用>

当我查看记录时,其中一些记录将 INFORMATION_SCHEMA 作为 table_schema。

<块引用>

Identifiers

当标识符不带引号时,它以大写形式存储和解析。

问题是您正在比较不同的大写和小写字符串。

where table_schema LIKE '%information%';  -- this comparison will not work

其他比较方式:

where table_schema LIKE UPPER('%information%');

值得注意的是,SHOW TABLES LIKE '<patern>' 在设计上不区分大小写,无论使用何种版本,都会返回以下匹配项:

SHOW TABLES LIKE '%information%';
SHOW TABLES LIKE '%INFORMATION%';
SHOW TABLES LIKE '%Information%';