From: Bricklen Anderson <banderson@presinet.com>
To: Gerardo Herzig <gherzig@fmed.uba.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: spliting a row to make several rows
Date: Thu, 12 Oct 2006 15:42:44 -0700
Message-ID: <452EC4E4.90107@presinet.com> (raw)
In-Reply-To: <452EBF1F.7070505@fmed.uba.ar>
References: <452EBF1F.7070505@fmed.uba.ar>
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;
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: banderson@presinet.com, gherzig@fmed.uba.ar
Subject: Re: spliting a row to make several rows
In-Reply-To: <452EC4E4.90107@presinet.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