Re: Split a string to rows?

Поиск
Список
Период
Сортировка
От Jonathan S. Katz
Тема Re: Split a string to rows?
Дата
Msg-id 747F3D71-64DE-4697-B5D5-D6476563801F@excoventures.com
обсуждение исходный текст
Ответ на Split a string to rows?  (Emi Lu <emilu@encs.concordia.ca>)
Ответы Re: Split a string to rows?  (Emi Lu <emilu@encs.concordia.ca>)
Список pgsql-sql
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


В списке pgsql-sql по дате отправления:

Предыдущее
От: Steve Crawford
Дата:
Сообщение: Re: Split a string to rows?
Следующее
От: Emi Lu
Дата:
Сообщение: Re: Split a string to rows?