Home > Net >  SQL - convert into regex
SQL - convert into regex

Time:11-05

Any ideas how to convert into regex?

SELECT * 
FROM my_table 
WHERE series LIKE 'X-1' 
   OR series LIKE 'X-2' 
   OR series LIKE 'X-3'

WHERE series too repetitive.

CodePudding user response:

You can use the 'pipe' inside the regex with the keyword 'SIMILAR TO' instead of using 'OR' multiple times

SELECT * FROM my_table WHERE series SIMILAR TO '(X-1|X-2|X-3)'

Ref: https://dataschool.com/how-to-teach-people-sql/how-regex-works-in-sql/

  •  Tags:  
  • sql
  • Related