简体   繁体   中英

Snowflake regexp return zero rows

I've got a strange scenario in Snowflake that i am not too sure how to solve. I have some data in a column that looks like this -

ID, Names
1, Google | Bing | BAU | Sale
2, BAU | Sale | Bing
3, Google | Bing

I am attempting to use REGEXP to pull out anyrows that match my pattern like so -

where Name regexp ('Google|Bing')

Which i was hoping would return all 3 rows - at this stage i get zero.

Appreciate any help you guys can offer

SELECT column1 
    ,regexp_count(column1, 'Google|Bing')
FROM VALUES
('Google | Bing | BAU | Sale'),
('BAU | Sale | Bing'),
('Google | Bing');

gives:

COLUMN1 REGEXP_COUNT(COLUMN1, 'GOOGLE|BING')
Google | Bing | BAU | Sale 2
BAU | Sale | Bing 1
Google | Bing 2

so the pattern matches something...

SELECT column1 
FROM VALUES
    ('Google | Bing | BAU | Sale'),
    ('BAU | Sale | Bing'),
    ('Google | Bing')
WHERE column1 regexp '.*(Google|Bing).*';

works

COLUMN1
Google | Bing | BAU | Sale
BAU | Sale | Bing
Google | Bing

because :

The function implicitly anchors a pattern at both ends (ie '' automatically becomes '^$', and 'ABC' automatically becomes '^ABC$'). To match any string starting with ABC, the pattern would be 'ABC.*'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM