Re: spliting a row to make several rows

From: Bricklen Anderson <banderson(at)presinet(dot)com>
To: Gerardo Herzig <gherzig(at)fmed(dot)uba(dot)ar>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: spliting a row to make several rows
Date: 2006-10-12 22:42:44
Message-ID: 452EC4E4.90107@presinet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Gerardo Herzig 2006-10-12 23:00:45 Re: spliting a row to make several rows
Previous Message Gerardo Herzig 2006-10-12 22:18:07 spliting a row to make several rows