Total Pageviews

2018/08/12

[PostgreSQL] How to retrieve a value which separated by comma

Problem
I retrieve 3 records via the following SQL statement:
  select id,  domain_projects 
  from project
  where domain_classifier = true 



The value in domain_projects column is separated by comma, if I would like to pick up the value which contains 26, how to do it?




How-To
Here has SQL statement:
  select id,  domain_projects 
  from project
  where domain_classifier = true 
        and '26' = any(string_to_array(domain_projects, ',')) 






Reference
[1] https://www.postgresql.org/docs/9.1/static/functions-array.html
[2] https://www.postgresql.org/docs/9.1/static/functions-comparisons.html

No comments: