Remove characters before ( in snowflake

1.1k Views Asked by At

I wanted to remove any character before ( in snowflake. For example: If the data has "Hello(World)", I want only "(World)".

3

There are 3 best solutions below

0
Lukasz Szozda On BEST ANSWER

Using SUBSTR and CHARINDEX functions:

CREATE TABLE tab AS SELECT 'Hello(World)' AS col;

SELECT SUBSTR(col, CHARINDEX('(', col))
FROM tab;
-- (World)
0
Greg Pavlik On

You can use the regexp_substr function to extract text and use a greedy expression:

set str = 'Hello (world)';

select regexp_substr($str, '\\((.+)\\)');
0
Mike Walton On

I'm a big fan of SPLIT and SPLIT_PART

CREATE TABLE tab AS SELECT 'Hello(World)' AS col;

SELECT '(' || SPLIT_PART(col, '(', 2)
FROM tab;
-- (World)