Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 0E3C79FB3D2 for ; Thu, 12 Oct 2006 19:42:55 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 71020-05 for ; Thu, 12 Oct 2006 22:42:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 542889FA4C5 for ; Thu, 12 Oct 2006 19:42:48 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from presinet.com (mail.presinet.com [209.53.156.1]) by svr4.postgresql.org (Postfix) with ESMTP id 72A845AF8AA for ; Thu, 12 Oct 2006 22:42:47 +0000 (GMT) Received: from [10.10.1.151] ([10.10.1.151]) by presinet.com with Microsoft SMTPSVC(6.0.3790.1830); Thu, 12 Oct 2006 15:40:14 -0700 Message-ID: <452EC4E4.90107@presinet.com> Date: Thu, 12 Oct 2006 15:42:44 -0700 From: Bricklen Anderson User-Agent: Thunderbird 1.5.0.7 (X11/20060922) MIME-Version: 1.0 To: Gerardo Herzig Cc: pgsql-sql@postgresql.org Subject: Re: spliting a row to make several rows References: <452EBF1F.7070505@fmed.uba.ar> In-Reply-To: <452EBF1F.7070505@fmed.uba.ar> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 12 Oct 2006 22:40:14.0703 (UTC) FILETIME=[62619FF0:01C6EE4F] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200610/121 X-Sequence-Number: 26510 Gerardo Herzig wrote: > Hi all: What a want to do is something like this: > suppose i have this record > > aa--bb--cc > > I guess if im able to do some sql/plsql procedure to get something like it > aa > bb > cc > (3 records, rigth?) > > Thanks a lot > Gerardo > dev=#select split_to_rows('aa--bb--cc','--'); split_to_rows --------------- aa bb cc (3 rows) This function was written by David Fetter, http://archives.postgresql.org/pgsql-general/2005-12/msg00080.php CREATE OR REPLACE FUNCTION split_to_rows(TEXT,TEXT) RETURNS SETOF TEXT AS $$ SELECT (string_to_array($1, $2))[s.i] FROM generate_series( 1, array_upper(string_to_array($1, $2), 1) ) AS s(i); $$ language sql strict;