From: | Sam Mason <sam(at)samason(dot)me(dot)uk> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org |
Subject: | Re: [HACKERS] string_to_array with empty input |
Date: | 2009-04-02 18:24:16 |
Message-ID: | 20090402182416.GQ12225@frubble.xen.chris-lamb.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
On Thu, Apr 02, 2009 at 02:04:41PM -0400, Tom Lane wrote:
> A correct fix
> outside-the-function would look more like
>
> case when str = '' then '{}'::text[] else string_to_array(str, ',') end
>
> which should correctly yield NULL for NULL input and an empty array
> for empty input. Similarly, if someone wanted to force the
> single-empty-string result, they should do
>
> case when str = '' then '{""}'::text[] else string_to_array(str, ',') end
>
> which also still yields NULL if str is NULL.
>
> Right at the moment, if we stick with the historical definition
> of the function, *both* camps have to write out their choice of
> the above. Seems like this is the worst of all possible worlds.
> We should probably pick one or the other.
Yes, I'd be tempted to pick one and go with it. It's seems a completely
arbitrary choice one way or the other but the current behaviour is
certainly wrong.
I'd go with returning a zero element array because it would do
the "right thing" more often when paired with array_to_string.
I've also been through the first few pages of a Google search for
"array_to_string" and it seems to do the "right" thing for the majority
of the cases.
--
Sam http://samason.me.uk/
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Haas | 2009-04-02 18:37:21 | Re: [HACKERS] string_to_array with empty input |
Previous Message | Tom Lane | 2009-04-02 18:18:31 | Re: [HACKERS] string_to_array with empty input |
From | Date | Subject | |
---|---|---|---|
Next Message | Heikki Linnakangas | 2009-04-02 18:32:20 | Re: 8.4 open items list |
Previous Message | Heikki Linnakangas | 2009-04-02 18:19:46 | Re: [HACKERS] Mentors needed urgently for SoC & PostgreSQL Student Internships |