Re: string_to_array with an empty input string - Mailing list pgsql-hackers

From Greg Stark
Subject Re: string_to_array with an empty input string
Date
Msg-id AANLkTimLmEc46Hi0Jt-0-VphnsePbkwzq3mKiNYddwg4@mail.gmail.com
Whole thread Raw
In response to Re: string_to_array with an empty input string  (Peter Geoghegan <peter.geoghegan86@gmail.com>)
Responses Re: string_to_array with an empty input string
Re: string_to_array with an empty input string
Re: string_to_array with an empty input string
List pgsql-hackers
On Wed, Aug 11, 2010 at 12:37 AM, Peter Geoghegan
<peter.geoghegan86@gmail.com> wrote:
> On 10 August 2010 19:48, David E. Wheeler <david@kineticode.com> wrote:
>> On Aug 10, 2010, at 11:46 AM, Thom Brown wrote:
>>
>>> I, personally, would expect an empty array output given an empty
>>> input, and a null output for a null input.
>>
>> +1
>
> Agreed. After all, the result isn't indeterminate - it's an empty
> array. Some people might think that it's useful for the result to be
> NULL, but they'd probably also think that it's useful for an empty
> string to be NULL.
>

For what it's worth there are two reasonable return values for
string_to_array(''). It could be [] or it could be ['']. There are
applications where the former makes the most sense and there are
applications where the latter makes the most sense.

Ideally you really want string_to_array(array_to_string(x, ':'),':')
to return x. There's no safe return value to pick for the cases where
x=[''] and x=[] that will make this work.

-- 
greg


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: assertions and constraint triggers
Next
From: Greg Stark
Date:
Subject: Re: string_to_array with an empty input string