Re: Splitting text column to multiple rows

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Splitting text column to multiple rows
Date: 2010-03-28 20:48:28
Message-ID: E71C42D277C84916A9A8A88A6F11ED87@andrusnotebook
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> CREATE OR REPLACE FUNCTION unnest(anyarray)
> RETURNS SETOF anyelement as $$
> SELECT $1[i] FROM generate_series(1,4) g(i)
> $$ LANGUAGE sql;
>
> pavel(at)postgres:5481=# select unnest(string_to_array('23,2,3,4,5',','));

I tried code below. Order of rows in result is different from the order of
elements in string.
How to preserve element order ?

Andrus.

create temp table person2 ( id char(9)) on commit drop;
insert into person2 values ('9'),('8');
CREATE OR REPLACE FUNCTION unnest(anyarray)
RETURNS SETOF anyelement as $$
SELECT $1[i] FROM generate_series(1,4) g(i)
$$ LANGUAGE sql;

select * from (select unnest(string_to_array('9,23,8,7,4,5',',')) ) xx,
person2
order by id;

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bopolissimus Platypus Jr 2010-03-28 21:36:03 Re: Achieving ordered update
Previous Message Andrus 2010-03-28 20:48:20 Re: How to perform text merge