sql - LIKE 运算符两列 clickhouse
问题描述
我想在 clickhouse 表中选择两个字符串列彼此相似的行(foe example where column1 is 'Hello' and column2 is '%llo'
)
我试过 LIKE 运算符:
SELECT * FROM table_name WHERE column1 LIKE column2;
但它说:
Received exception from server (version 21.2.8):
Code: 44. DB::Exception: Received from localhost:9000. DB::Exception: Argument at index 1 for function like must be constant: while executing 'FUNCTION like(column1 : 17, column2 : 17) -> like(column1, column2) UInt8 : 28'.
似乎第二个参数应该是一个常数值。有没有其他方法可以应用这个条件?
解决方案
You can use LOCATE
or POSITION
for this (https://clickhouse.tech/docs/en/sql-reference/functions/string-search-functions/). The query would look something like this:
SELECT *
FROM table_name
WHERE position(column1, column2, character_length(column1) - character_length(column2) + 1) > 0;
This may be flawed. It seems that in clickhouse most string functions work on bytes or variable UTF8 byte lengths rather than on characters. One has to pay attentention hence how the functions work and how they should be combined. I am using the third parameter start_pos
above and assume that it refers to the character position, but well, it can be bytes just as well - I have not been able to find this information in the docs .
推荐阅读
- c++ - 需要帮助我如何获得不同的输出
- android - 需要权限时 IDE 的问题
- python - 如何在不中断我的 tkinter 主循环的情况下运行一个函数,同时将该函数的信息发送到我的主循环中的小部件?
- c++ - 如何找出发生浮点异常的位置?
- sql - 为每个 ID 选择具有最新日期的数据
- c# - 使用 excel 的服务中的方法未保存并且似乎不会产生异常
- python - 获取文本格式的摘要计数
- python - 来自 Tensorflow TextLineDataset 的 Ngram
- .net - .NET 4.6.1 和 TLS 1.0 服务器中的 WCF/SOAP 客户端:缺少客户端问候
- swift - 如何从结构中获取随机值