替换包含第一个列表(模式)中某些元素的文本,然后替换为Clickhouse中其他列表(替换)中的元素
你好,我有这个表
WITH datos as (WITH ['This not change','this text is the second word','this is a exact mach','and this not change'] as datosSup
select arrayJoin(datosSup) as Title)
select * from datos
我的表
标题 |
---|
第一个单词 |
这个文字是第二个单词 |
,这是一个确切的马赫 |
,这不是更改 |
和两个列表,
['is the second word','this is a exact mach'] as patterns,
['contains second word','replaced text exact match'] as replacements
我能够替换文本,如果“ title title < /em>“字段精确匹配列表模式的一个元素
WITH datos as (WITH ['first word','this text is the second word','this is a exact mach','and this not change'] as datosSup
select arrayJoin(datosSup) as Title),
['is the second word','this is a exact mach'] as pattern,
['contains second word','replaced text exact match'] as replacement
select if(indexOf(pattern,Title)>0,replacement[indexOf(pattern,Title)],Title) from datos
结果:
标题 |
---|
第一个单词 |
此文本是第二个单词 |
替换文本精确匹配 |
,而这不是更改 |
,但我想替换文本,包含 /strong>第一个列表中的某些元素(模式),并替换为其他列表中的元素(替换)。
所需结果:
标题 |
---|
第一字 |
此文本包含第二个字 |
替换文本精确匹配 |
,而这不会改变 |
Hello I have this table
WITH datos as (WITH ['This not change','this text is the second word','this is a exact mach','and this not change'] as datosSup
select arrayJoin(datosSup) as Title)
select * from datos
My Table
Title |
---|
first word |
this text is the second word |
this is a exact mach |
and this not change |
And two lists,
['is the second word','this is a exact mach'] as patterns,
['contains second word','replaced text exact match'] as replacements
I have been able to replace text if "Title" field exact match with one element of list patterns
WITH datos as (WITH ['first word','this text is the second word','this is a exact mach','and this not change'] as datosSup
select arrayJoin(datosSup) as Title),
['is the second word','this is a exact mach'] as pattern,
['contains second word','replaced text exact match'] as replacement
select if(indexOf(pattern,Title)>0,replacement[indexOf(pattern,Title)],Title) from datos
Result:
Title |
---|
first word |
this text is the second word |
replaced text exact match |
and this not change |
But I want replace text which contains some element from first list (patterns) and replace it by elements in other list (replacements).
Result desired:
Title |
---|
first word |
this text contains second word |
replaced text exact match |
and this not change |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以防万一它可以帮助任何人,我在另一个论坛中回答,如下所示,
表P为(模式字符串,替换字符串)。不幸的是,Clickhouse的替换()仅用于模式和更换。因此,我制作了一个函数my_replace
结果
Just in case it helps anyone, I was answered in another forum as follows
Table p is (pattern String, replacement String). Unfortunately ClickHouse's REPLACE() takes constant only for pattern and replacement. So I made a function my_replace
Result