Re: [HACKERS] string_to_array with empty input

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [HACKERS] string_to_array with empty input
Date: 2009-04-02 16:29:04
Message-ID: 49D4E7D0.2090704@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Leif B. Kristensen wrote:
> On Thursday 2. April 2009, Steve Crawford wrote:
>
>> Currently string_to_array(null, ',') yields a null result -
>> indistinguishable from string_to_array('',','). Wrapping in coalesce
>> does not help distinguish true null input from empty-string input. I'm
>> not sure at the moment what other cases exist where non-null input
>> generates null output.
>>
>
> Somehow this reminds me of the old "division by zero" problem.
>
> IMO, the proper way to handle this kind of anomaly would be to test if
> the length of the string is non-zero before submitting it to the
> string_to_array() function.
>
Quite the opposite. Where division by zero is simply illegal as is, say,
string_to_array(1234, ','), string_to_array('', ',') is legal.
Unfortunately it is legal, and legal and legal.... with numerous
reasonable interpretations of which legal is most appropriate/consistent.

I would argue against a change to have string_to_array('',',') throw an
error.

Cheers,
Steve

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Clark 2009-04-02 16:46:41 Re: cast needed - but where and why?
Previous Message Sam Mason 2009-04-02 16:27:55 Re: reducing IO and memory usage: sending the content of a table to multiple files

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2009-04-02 17:11:23 Re: [COMMITTERS] pgsql: If we expect a hash join to be performed in multiple batches,
Previous Message Werner Echezuria 2009-04-02 16:21:34 Re: Sort a column that does not exist