Re: Splitting text column to multiple rows - Mailing list pgsql-general

From Andrus
Subject Re: Splitting text column to multiple rows
Date
Msg-id E71C42D277C84916A9A8A88A6F11ED87@andrusnotebook
Whole thread Raw
In response to Re: Splitting text column to multiple rows  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: Splitting text column to multiple rows
List 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@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;


pgsql-general by date:

Previous
From: "Andrus"
Date:
Subject: Re: How to perform text merge
Next
From: Bopolissimus Platypus Jr
Date:
Subject: Re: Achieving ordered update