Re: string_to_array with empty input - Mailing list pgsql-general

From Greg Stark
Subject Re: string_to_array with empty input
Date
Msg-id 4136ffa0903311053x6f80e0bbl384167a71005aece@mail.gmail.com
Whole thread Raw
In response to Re: string_to_array with empty input  (justin <justin@emproshunts.com>)
Responses Re: string_to_array with empty input
List pgsql-general
On Tue, Mar 31, 2009 at 6:44 PM, justin <justin@emproshunts.com> wrote:
>
> Consider this.  I have intelligent part numbers  that need to be split apart
> to simplify searching  and do math with.
>
> string_to_array(' F-2500-50 ', '-' ) ::int[]

Yeah, that's what I've said about three times. If you're building a
parser and think of it in terms of string parsing then yes, a
singletone array makes sense.

> Still fails with an error as expected.  what is the difference between ' '
> and 'F'

I don't know what you're talking about. The question is how many
elements are in ''. No space. And no separators. To repeat for the
last time. If you think in terms of string processing then the answer
1 is reasonable. But if you think it's a list of separate items then
anyone will say that's an empty list and contains no elements.

Nobody has ever suggested filtering out empty elements or dealing
specially with spaces or anything else like that. If you're talking
about that then you've missed the original question.

One last try.

If there's a column called "shopping list" which is a comma-separated
list of items to buy in the store and I store '' in it. How many items
do you think that means you should go shopping for? Do you think
that's one item that should be rejected because it's an empty string?
Or do you think that's an empty list with zero items listed?

What would it look like if it was a zero-length list? You can ask what
would it look like if it was a shopping list of one item called ''.
But I agree both are theoretically consistent, but one is actually
useful in 99% of use cases. The other is only useful in unusual cases.
--
greg

pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Pg Conference East: Registration closing
Next
From: justin
Date:
Subject: Re: string_to_array with empty input