Search Postgresql Archives

Re: Splitting text column to multiple rows

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/3/29 Andrus <kobruleht2@xxxxxx>:
> 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@xxxxxxxxxxxxx>
> To: "Andrus" <kobruleht2@xxxxxx>
> Cc: "Pavel Stehule" <pavel.stehule@xxxxxxxxx>;
> <pgsql-general@xxxxxxxxxxxxxx>
> Sent: Monday, March 29, 2010 6:00 PM
> Subject: Re:  Splitting text column to multiple rows
>
>
>> "Andrus" <kobruleht2@xxxxxx> 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
>
>

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux