此页面涉及 Explore 的一部分
case_sensitive参数。
case_sensitive还可以用作模型的一部分,如case_sensitive(针对模型)参数文档页面中所述。
case_sensitive还可以用作维度的一部分,如case_sensitive(针对字段)参数文档页面中所述。
用法
explore: explore_name {
case_sensitive: yes
}
|
层次结构
case_sensitive |
默认值
yes(如果数据库方言支持相应参数)
接受
布尔值(yes 或 no)
|
定义
case_sensitive 用于确定在给定的 Explore 中,过滤条件是否区分大小写。与探索相关的所有过滤条件都会受到影响,包括在探索界面、信息中心界面和 filters 参数中添加的过滤条件。
默认情况下,case_sensitivity 处于开启状态,并且过滤条件区分大小写。不过,如本页面的某些 SQL 方言不支持 case_sensitive 部分中所述,某些方言不支持此参数。
case_sensitive 的工作原理是调整 Looker 生成的 SQL 的 WHERE 子句。当 case_sensitive 处于开启状态时,过滤条件会以 = 或 LIKE 表示,例如:
WHERE name = 'bob'
WHERE name LIKE '%bob%'
当 case_sensitive 处于关闭状态时,过滤条件会使用 ILIKE(或等效项)表示,例如:
WHERE name ILIKE 'bob'
示例
使产品探索中的所有过滤条件都区分大小写:
explore: product {
case_sensitive: yes
}
使客户探索中的所有过滤条件都不区分大小写:
explore: customer {
case_sensitive: no
}
常见挑战
某些 SQL 方言不支持 case_sensitive
默认情况下,case_sensitivity 处于开启状态,并且过滤条件区分大小写。如果您的 SQL 方言不支持 case_sensitive 参数,区分大小写的情况将因数据库设置而异,但通常不区分大小写。
为了让 Looker 在您的 Looker 项目中支持 case_sensitive,您的数据库方言也必须支持它。下表显示了 Looker 最新版本中哪些方言支持 case_sensitive:
| 方言 | 是否支持? |
|---|---|
| Actian Avalanche | |
| Amazon Athena | |
| Amazon Aurora MySQL | |
| Amazon Redshift | |
| Amazon Redshift 2.1+ | |
| Amazon Redshift Serverless 2.1+ | |
| Apache Druid | |
| Apache Druid 0.13+ | |
| Apache Druid 0.18+ | |
| Apache Hive 2.3+ | |
| Apache Hive 3.1.2+ | |
| Apache Spark 3+ | |
| ClickHouse | |
| Cloudera Impala 3.1+ | |
| Cloudera Impala 3.1+ with Native Driver | |
| Cloudera Impala with Native Driver | |
| DataVirtuality | |
| Databricks | |
| Denodo 7 | |
| Denodo 8 & 9 | |
| Dremio | |
| Dremio 11+ | |
| Exasol | |
| Google BigQuery Legacy SQL | |
| Google BigQuery Standard SQL | |
| Google Cloud PostgreSQL | |
| Google Cloud SQL | |
| Google Spanner | |
| Greenplum | |
| HyperSQL | |
| IBM Netezza | |
| MariaDB | |
| Microsoft Azure PostgreSQL | |
| Microsoft Azure SQL Database | |
| Microsoft Azure Synapse Analytics | |
| Microsoft SQL Server 2008+ | |
| Microsoft SQL Server 2012+ | |
| Microsoft SQL Server 2016 | |
| Microsoft SQL Server 2017+ | |
| MongoBI | |
| MySQL | |
| MySQL 8.0.12+ | |
| Oracle | |
| Oracle ADWC | |
| PostgreSQL 9.5+ | |
| PostgreSQL pre-9.5 | |
| PrestoDB | |
| PrestoSQL | |
| SAP HANA | |
| SAP HANA 2+ | |
| SingleStore | |
| SingleStore 7+ | |
| Snowflake | |
| Teradata | |
| Trino | |
| Vector | |
| Vertica |
注意事项
您可以在 MySQL 中创建区分大小写的搜索
即使 MySQL 不支持 case_sensitive 参数,也可以在 MySQL 中创建区分大小写的搜索。在 MySQL 中,某些数据类型(称为二进制字符串)会将文本存储为一系列数字。文本的大小写会影响所使用的数字。因此,如果您将文本转换为二进制字符串,就可以进行区分大小写的搜索。例如:
dimension: will_NOT_be_case_sensitive {
sql: ${TABLE}.something ;;
}
dimension: will_be_case_sensitive {
sql: CAST(${TABLE}.something AS BINARY) ;;
}