Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
572 views
in Technique[技术] by (71.8m points)

regex - Finding string that has repeated pattern in snowflake

I am trying to find the string that has repeated patterns in snowflake table. I am trying to get that using regex.

Example : String : 'abc' , 'abcabc' , 'snowsnowflake'

The Query return only " 'abcabc' , 'snowsnowflake' ". Because it has repeated patterns.

Thank you.

question from:https://stackoverflow.com/questions/65879708/finding-string-that-has-repeated-pattern-in-snowflake

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I couldn't make it work with plain regex in SQL, but I was able to create a JavaScript UDF to get the desired results:

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...