pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
spliting a row to make several rows
3+ messages / 2 participants
[nested] [flat]

* spliting a row to make several rows
@ 2006-10-12 22:18  Gerardo Herzig <gherzig@fmed.uba.ar>
  0 siblings, 1 reply; 3+ messages in thread

From: Gerardo Herzig @ 2006-10-12 22:18 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: spliting a row to make several rows
@ 2006-10-12 22:42  Bricklen Anderson <banderson@presinet.com>
  parent: Gerardo Herzig <gherzig@fmed.uba.ar>
  0 siblings, 1 reply; 3+ messages in thread

From: Bricklen Anderson @ 2006-10-12 22:42 UTC (permalink / raw)
  To: Gerardo Herzig <gherzig@fmed.uba.ar>; +Cc: 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;



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: spliting a row to make several rows
@ 2006-10-12 23:00  Gerardo Herzig <gherzig@fmed.uba.ar>
  parent: Bricklen Anderson <banderson@presinet.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Gerardo Herzig @ 2006-10-12 23:00 UTC (permalink / raw)
  To: Bricklen Anderson <banderson@presinet.com>; +Cc: pgsql-sql

Cool!! Thanks a lot! I will try it as soon as possible

Gerardo

> 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;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly
>
>




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2006-10-12 23:00 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-10-12 22:18 spliting a row to make several rows Gerardo Herzig <gherzig@fmed.uba.ar>
2006-10-12 22:42 ` Bricklen Anderson <banderson@presinet.com>
2006-10-12 23:00   ` Gerardo Herzig <gherzig@fmed.uba.ar>

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