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 
--------
 a
 b
 c
(3 rows)

If you need a more complex string splitting mechanism, there is the 
"regexp_split_to_array" function.

Jonathan

-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

Reply via email to