Friday, June 19, 2009

Convert a comma separated column or string value as a sub query result or rows

Here rmid is looks like '1,2,3,4,5,6'

select
           *
from
           menu m
           left outer join roles r
on
           r.rid = 3
where
           select
                   m.mid
           in
                   (select
                           regexp_split_to_table(r.mid,',')::int
                    )



Another example,



SELECT
         
       foo
FROM
           
    regexp_split_to_table('the1quick2brown3fox4jumped over the,lazy,dog',E'[\\,\\\s1-9]+') AS foo




Ref: http://www.postgresql.org/docs/8.3/static/functions-matching.html

No comments:

Post a Comment