Skip site navigation (1) Skip section navigation (2)

Re: Splitting text column to multiple rows

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-general(at)postgresql(dot)org
Subject: Re: Splitting text column to multiple rows
Date: 2010-03-29 15:17:35
Message-ID: 162867791003290817u12ff8068l85bb6af0fb26b0a@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
2010/3/29 Andrus <kobruleht2(at)hot(dot)ee>:
> This returns 5 rows:
>
> CREATE OR REPLACE FUNCTION unnest(anyarray)
> RETURNS SETOF anyelement as $$
>  SELECT $1[i] FROM generate_series(1,4) g(i) <<--- 4 is constant !!!!!!!!!!!!
> $$ LANGUAGE sql;
>
> select unnest(string_to_array('23,2,3,4,5',','));
>
> simply changing name returns 4 rows:

sure .. original buggy function is here still.

Pavel

>
> 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(at)sss(dot)pgh(dot)pa(dot)us>
> To: "Andrus" <kobruleht2(at)hot(dot)ee>
> Cc: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>;
> <pgsql-general(at)postgresql(dot)org>
> Sent: Monday, March 29, 2010 6:00 PM
> Subject: Re: [GENERAL] Splitting text column to multiple rows
>
>
>> "Andrus" <kobruleht2(at)hot(dot)ee> writes:
>>>
>>> Pavel,
>>>>
>>>> pavel(at)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
>
>

In response to

pgsql-general by date

Next:From: Pavel StehuleDate: 2010-03-29 15:18:30
Subject: Re: Splitting text column to multiple rows
Previous:From: Tom LaneDate: 2010-03-29 15:17:12
Subject: Re: Splitting text column to multiple rows

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group