查找雪花中具有重复模式的字符串

问题描述

我正在尝试查找雪花表中具有重复模式的字符串。我正在尝试使用正则表达式来实现。

示例: 字符串:'abc','abcabc','sNowsNowflake'

查询仅返回“ 'abcabc','sNowsNowflake' ”。因为它有重复的模式。

谢谢。

解决方法

我无法在 SQL 中使用普通的正则表达式,但我能够创建一个 JavaScript UDF 以获得所需的结果:

create or replace function find_repeated("x" string)
returns string
language javascript
as
$$
return x.match(/(.+)\1/g)
$$;

select x.value,find_repeated(x.value),find_repeated(x.value) is not null has_repeated
from table(split_to_table('abc,abcabc,snowsnowflake',',')) x

enter image description here