Re: Split a string to rows?

From: Emi Lu <emilu(at)encs(dot)concordia(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Cc: "Jonathan S(dot) Katz" <jonathan(dot)katz(at)excoventures(dot)com>
Subject: Re: Split a string to rows?
Date: 2013-01-07 20:21:18
Message-ID: 50EB2E3E.2020406@encs.concordia.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

All right. I found the function.
http://wiki.postgresql.org/wiki/Array_Unnest

Thanks a lot!
Emi

On 01/07/2013 03:16 PM, Emi Lu wrote:
> Thanks a lot! I just noticed that my postgresql is 8.3(unnest function
> is not there by default). Is there a way that I could download and load
> only this function from somewhere?
>
> Thanks again!
> Emi
>
>
> On 01/07/2013 02:58 PM, Jonathan S. Katz wrote:
>> 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
>>
>
>

--
Emi Lu, ENCS, Concordia University, Montreal H3G 1M8
emilu(at)encs(dot)concordia(dot)ca +1 514 848-2424 x5884

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Kellerer 2013-01-07 20:31:32 Re: Split a string to rows?
Previous Message Emi Lu 2013-01-07 20:16:25 Re: Split a string to rows?