Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TsIqo-0002Uk-2v for pgsql-sql@arkaria.postgresql.org; Mon, 07 Jan 2013 19:59:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TsIqm-0006Am-JI for pgsql-sql@arkaria.postgresql.org; Mon, 07 Jan 2013 19:59:12 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TsIqc-00062B-NR for pgsql-sql@postgresql.org; Mon, 07 Jan 2013 19:59:02 +0000 Received: from mail-ie0-f170.google.com ([209.85.223.170]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TsIqb-0000Jl-1P for pgsql-sql@postgresql.org; Mon, 07 Jan 2013 19:59:02 +0000 Received: by mail-ie0-f170.google.com with SMTP id k10so24541697iea.1 for ; Mon, 07 Jan 2013 11:59:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:subject:mime-version:content-type:from:in-reply-to:date :cc:content-transfer-encoding:message-id:references:to:x-mailer :x-gm-message-state; bh=12YJJqY4q/JVvLJLBaSA1QV/05Qa/8pWVuQe9LncCtc=; b=CHhNY46Rk5DCLsFekBUHhP8SBd7s98PQOi03gqbM3DsNGyOmBUvLMDDhzDmMdrHf9O XBKoe7Mh0HfXBKqcM43R3luD7CVyqzaeu46b20vUwD28ZjvD0KeVsKDDsexlIWKclnGY MsXtFqZUhaW7flZ924AboOaXgCGSPwCk1jxxV2Y1U+VvIZlGcX2ZOpiBB3jJmRGruLUG WQh3Bj0dYNS1TLuo4al7FDQJN+pOwcvODLca/JyNNq+CZGi6iKHtc7TwOT1DQkdhojw/ 6vi068e7JyhwDbTu5CB0j+pr9xwxPPylneDHbR3qOYAi5Ue3+GIy3nsZZqOSjNaDTzLJ hwwA== X-Received: by 10.50.53.226 with SMTP id e2mr6639400igp.92.1357588739990; Mon, 07 Jan 2013 11:58:59 -0800 (PST) Received: from ph33r-retina.home (pool-100-2-123-209.nycmny.fios.verizon.net. [100.2.123.209]) by mx.google.com with ESMTPS id bh3sm7784868igc.0.2013.01.07.11.58.58 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 07 Jan 2013 11:58:59 -0800 (PST) Subject: Re: Split a string to rows? Mime-Version: 1.0 (Apple Message framework v1280) Content-Type: text/plain; charset=iso-8859-1 From: "Jonathan S. Katz" In-Reply-To: <50EB25B5.5020502@encs.concordia.ca> Date: Mon, 7 Jan 2013 14:58:57 -0500 Cc: pgsql-sql@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <747F3D71-64DE-4697-B5D5-D6476563801F@excoventures.com> References: <50EB25B5.5020502@encs.concordia.ca> To: emilu@encs.concordia.ca X-Mailer: Apple Mail (2.1280) X-Gm-Message-State: ALoCoQkfuoLSW52m5GZB+kFHkiKkaVfn0ypJf+I4lBqObS8v374m4msYT7OXLip49tahl26U181d X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On Jan 7, 2013, at 2:44 PM, Emi Lu wrote: > Hello, >=20 > Is there a function to split a string to different rows? >=20 > For example, t1(id, col1) > values(1, 'a, b, c'); >=20 > select id, string_split_to_row(col1, ','); >=20 > Return: > =3D=3D=3D=3D=3D=3D=3D=3D=3D > 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=20 -------- a b c (3 rows) If you need a more complex string splitting mechanism, there is the "regexp= _split_to_array" function. Jonathan --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql