From: Jonathan S. Katz <jonathan.katz@excoventures.com>
To: emilu@encs.concordia.ca
Cc: pgsql-sql@postgresql.org
Subject: Re: Split a string to rows?
Date: Mon, 7 Jan 2013 14:58:57 -0500
Message-ID: <747F3D71-64DE-4697-B5D5-D6476563801F@excoventures.com> (raw)
In-Reply-To: <50EB25B5.5020502@encs.concordia.ca>
References: <50EB25B5.5020502@encs.concordia.ca>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
--------
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 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: jonathan.katz@excoventures.com, emilu@encs.concordia.ca
Subject: Re: Split a string to rows?
In-Reply-To: <747F3D71-64DE-4697-B5D5-D6476563801F@excoventures.com>
* 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