On Jan 7, 2013, at 2:44 PM, Emi Lu wrote:
> Hello,
>
> Is there a function to split a string to different rows?
>
> For example, t1(id, col1)
> values(1, 'a, b, c');
>
> select id, string_split_to_row(col1, ',');
>
> Return:
> =========
> 1, a
> 1, b
> 1, c
You can probably use some combination of "string_to_array" and "unnest"
e.g.
SELECT unnest(string_to_array('a,b,c', ','));
unnest
--------abc
(3 rows)
If you need a more complex string splitting mechanism, there is the "regexp_split_to_array" function.
Jonathan