pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Emi Lu <emilu@encs.concordia.ca>
To: Jonathan S. Katz <jonathan.katz@excoventures.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Split a string to rows?
Date: Mon, 07 Jan 2013 15:16:25 -0500
Message-ID: <50EB2D19.8030308@encs.concordia.ca> (raw)
In-Reply-To: <747F3D71-64DE-4697-B5D5-D6476563801F@excoventures.com>
References: <50EB25B5.5020502@encs.concordia.ca>
	<747F3D71-64DE-4697-B5D5-D6476563801F@excoventures.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

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@encs.concordia.ca        +1 514 848-2424 x5884


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



view thread (9+ messages)  latest in thread

Message-ID: <50EB2D19.8030308@encs.concordia.ca>
Permalink:  ../50EB2D19.8030308@encs.concordia.ca/
Also on:    postgresql.org/message-id/50EB2D19.8030308@encs.concordia.ca

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: emilu@encs.concordia.ca, jonathan.katz@excoventures.com
  Subject: Re: Split a string to rows?
  In-Reply-To: <50EB2D19.8030308@encs.concordia.ca>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox