Re: what is good solution for support NULL inside string_to_array function?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: what is good solution for support NULL inside string_to_array function?
Date: 2010-05-04 14:05:18
Message-ID: x2k162867791005040705z6f2979bds256cc3241e38d78d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2010/5/4 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:
> 2010/5/4 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> Josh Berkus <josh(at)agliodbs(dot)com> writes:
>>>> quietly removing NULL is maybe good for compatibility but is wrong for
>>>> functionality.
>>
>>> I agree.  I wasn't aware of this little misfeature.
>>
>>> Default display for NULL should be a zero-length string.
>>
>> That's just as broken as Pavel's suggestion.  Unless you have something
>> that is guaranteed distingishable from the output of any non-null value,
>> you really can't make a significant improvement here.
>>
>
> I wouldn't modify current two params string_to_array and
> array_to_string function. So there are not any default string (maybe
> empty string) for NULL. My proposal is new three params functions with
>>>>explicit<<< "null string" definition. This cannot break
> compatibility and enhance functionality - It is just short cut for
> code from my proposal - in C this functionality can by implemented
> much faster.

I did some coding - the patch can be very simple

postgres=# select array_to_string(array[1,2,3,4,5,null],',','*');
array_to_string
-----------------
1,2,3,4,5,*
(1 row)

Time: 0,501 ms
postgres=# select
string_to_array(array_to_string(array[1,2,3,4,5,null],',','*'),',','*');
string_to_array
------------------
{1,2,3,4,5,NULL}
(1 row)

Time: 0,617 ms

postgres=# select string_to_array('1,2,3,4,5,*',',','*')::int[];
string_to_array
------------------
{1,2,3,4,5,NULL}
(1 row)

Time: 0,652 ms

and then string_to_array and array_to_string are orthogonal with NULL.

Pavel

>
> Regards
> Pavel
>
>>                        regards, tom lane
>>
>

Attachment Content-Type Size
3params_arrayfce.diff application/octet-stream 3.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Erik Rijkers 2010-05-04 14:08:30 Re: Reg: SQL Query for Postgres 8.4.3
Previous Message Simon Riggs 2010-05-04 13:49:56 Re: max_standby_delay considered harmful