Re: [HACKERS] string_to_array with empty input - Mailing list pgsql-general

From Robert Haas
Subject Re: [HACKERS] string_to_array with empty input
Date
Msg-id 603c8f070904011228p524ff06ci266f3080c0d25048@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] string_to_array with empty input  (justin <justin@emproshunts.com>)
Responses Re: [HACKERS] string_to_array with empty input  (justin <justin@emproshunts.com>)
Re: [HACKERS] string_to_array with empty input  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
On Wed, Apr 1, 2009 at 1:05 PM, justin <justin@emproshunts.com> wrote:
> I'm still a hold out,  We are taking a string putting it into a array based
> on a delimiter.  That is very simple and straight forward.  Yet many argue
> if we want to cast this into another data type the function should deal with
> in limited cases.
>
> string_to_array('',',')::INT[]  works as proposed
>
> But
> string_to_array(',,,', ',' )::INT[]   Fails
> or
> string_to_array('1,2,,4', ',' )::INT[] Fails .

But... but... those aren't comma-separated lists of integers.  If they
were, it would work.

string_to_array('cow,dog,horse')::INT[] will also fail.

If you take 0 items of any type whatsoever and join them together with
commas, you will get the empty string.  It is also true that if you
join 1 item together with commas, you will get that item back, and if
that item is the empty string, you will now have the empty string.  I
think it's better to worry more about the first case because it
applies to any type at all, whereas the latter case ONLY applies in
situations where the empty string is a potentially legal value.

...Robert

pgsql-general by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] string_to_array with empty input
Next
From: Duco Fijma
Date:
Subject: %r in restore_command?