Re: [GENERAL] string_to_array with empty input - Mailing list pgsql-hackers

From Sam Mason
Subject Re: [GENERAL] string_to_array with empty input
Date
Msg-id 20090401191750.GG12225@frubble.xen.chris-lamb.co.uk
Whole thread Raw
In response to Re: [GENERAL] string_to_array with empty input  (Greg Stark <stark@enterprisedb.com>)
List pgsql-hackers
On Wed, Apr 01, 2009 at 07:40:16PM +0100, Greg Stark wrote:
> The existing behaviour of returning NULL is the only "consistent"
> choice since the correct value is "unknown". And one could argue that
> it's easier to replace NULL with the correct value if the programmer
> knows using coalesce than it is to replace either "" or {""}.

Couldn't a similar argument be applied for division by zero?  Since it's
not known whether the user wants to get a "divide by zero" exception or
"infinity" PG should return NULL and punt the choice to the user.

I think everybody would agree that this would be a bad thing to do!

> But I'm
> still leaning to thinking that using an arbitrary choice that at least
> gets most users intentions is better.

I'd agree; returning NULL and not forcing the user to make a choice
is a bad design decision---the user doesn't need to put a coalesce
in and hence their code will probably break in strange ways when
they're not expecting it.  Nobody suggest adding a third parameter to
string_to_array, please!

The general mantra that seems to apply here is "one good option is
better than two bad ones".

--
  Sam  http://samason.me.uk/

pgsql-hackers by date:

Previous
From: Hiroshi Inoue
Date:
Subject: Re: More message encoding woes
Next
From: Robert Haas
Date:
Subject: Re: [GENERAL] string_to_array with empty input