Take the 2-minute tour ×

I have a table with regular expressions which I need to use to filter rows from another table.
Something like:


Obviously, that doesn't work because that isn't the syntax and there are multiple rows in b that I need to iterate through.

I'm using PostgreSQL 8.3.

share|improve this question
Post some sample data n desired o/p –  SOaddict Mar 6 '12 at 20:44
Are you aware that SIMILAR TO does not use regular expressions, but its own peculiar set of patterns - which are internally rewritten into regular expressions? I recently wrote a comprehensive answer about that on dba.SE –  Erwin Brandstetter Mar 6 '12 at 23:58
You know that pg9.2 has been out for almost a year now, right? –  Andrew Mar 7 '12 at 0:30

1 Answer 1

up vote 5 down vote accepted

Perhaps doing a join would work? E.g.

SELECT a.*, b.regex
  FROM a JOIN b ON a.foo ~ b.regex

I'm afraid I'm not familiar enough with Postgres to say for certain, but this would be the ordinary way in SQL of iterating over rows. It should return a.foo multiple times if multiple regexes are matched.

share|improve this answer

Your Answer


