Total Pageviews

2018/08/08

[PostgreSQL] How to split string into multiple rows?

Problem
I have a table which name project:

the domain_projects column stored values which separated by comma.


I attemp to split domain_projects string into multiple rows:


How do to it?

How-To
Here has SQL statement to fulfill this requirement:
  select cast(unnest(string_to_array( (select domain_projects from project where id = :id), ',')) as int) as project_id



Reference
[1] https://www.postgresql.org/message-id/20100121190706.GA12363@tux
[2] https://www.postgresql.org/docs/9.2/static/functions-array.html

No comments: