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

From Andrus
Subject Re: Splitting text column to multiple rows
Date
Msg-id 20A71A87FA66485F9DB9B37A0F749888@andrusnotebook
Whole thread Raw
In response to Re: Splitting text column to multiple rows  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Splitting text column to multiple rows  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general
This returns 5 rows:

CREATE OR REPLACE FUNCTION unnest(anyarray)
RETURNS SETOF anyelement as $$
  SELECT $1[i] FROM generate_series(1,4) g(i)
$$ LANGUAGE sql;

select unnest(string_to_array('23,2,3,4,5',','));

simply changing name returns 4 rows:

CREATE OR REPLACE FUNCTION unnest21(anyarray)
RETURNS SETOF anyelement as $$
  SELECT $1[i] FROM generate_series(1,4) g(i)
$$ LANGUAGE sql;

select unnest21(string_to_array('23,2,3,4,5',','));

Andrus.

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Andrus" <kobruleht2@hot.ee>
Cc: "Pavel Stehule" <pavel.stehule@gmail.com>;
<pgsql-general@postgresql.org>
Sent: Monday, March 29, 2010 6:00 PM
Subject: Re: [GENERAL] Splitting text column to multiple rows


> "Andrus" <kobruleht2@hot.ee> writes:
>> Pavel,
>>> pavel@postgres:5481=# select unnest(string_to_array('23,2,3,4,5',','));
>>> unnest
>>> --------
>>> 23
>>> 2
>>> 3
>>> 4
>>> (4 rows)
>
>> Result is wrong: it must contain 5 rows.
>
> Surely that's a copy-and-paste mistake?  I get 5 rows from this example.
>
> regards, tom lane


pgsql-general by date:

Previous
From: Leif Biberg Kristensen
Date:
Subject: Re: insert into test_b (select * from test_a) with different column order
Next
From: Pavel Stehule
Date:
Subject: Re: Splitting text column to multiple rows