Search Postgresql Archives

Re: Convert of string to array problem

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

 



On Thu, Apr 29, 2010 at 8:52 AM, Thom Brown <thombrown@xxxxxxxxx> wrote:
> On 29 April 2010 13:35, Bård Grønbech <baard.gronbech@xxxxxxxxx> wrote:
>>
>> Have a string like '0.1;0.2;null;0.3' which I would like to convert
>> into a double precision[] array.
>>
>> Trying:
>>
>> select cast (string_to_array('0.1;0.2;null;0.3', ';') as float8[])
>>
>> gives me an error: invalid input syntax for type double precision: "null".
>>
>> Can anybody help me?
>>
>> -Bård
>>
>
> I believe string_to_array will take that null as a string called 'null',
> which it can't convert to a float8.

select array(select case when n='null' then null else n end from
unnest(string_to_array('0.1;0.2;null;0.3', ';')) as n);

?column?
--------------------
 {0.1,0.2,NULL,0.3}

merlin

-- 
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