How to use SQL LIKE condition with multiple values in PostgreSQL?

sorin picture sorin · Oct 18, 2012 · Viewed 175.9k times · Source

Is there any shorter way to look for multiple matches:

 SELECT * 
 from table 
 WHERE column LIKE "AAA%" 
    OR column LIKE "BBB%" 
    OR column LIKE "CCC%"

This questions applies to PostgreSQL 9.1, but if there is a generic solution it would be even better.

Answer

tozka picture tozka · Oct 18, 2012

Perhaps using SIMILAR TO would work ?

SELECT * from table WHERE column SIMILAR TO '(AAA|BBB|CCC)%';