Re: string_to_array with empty input

From: Greg Stark <stark(at)enterprisedb(dot)com>
To: justin <justin(at)emproshunts(dot)com>
Cc: Sam Mason <sam(at)samason(dot)me(dot)uk>, pgsql-general(at)postgresql(dot)org, pgsql-hackers(at)postgresql(dot)org
Subject: Re: string_to_array with empty input
Date: 2009-03-31 17:53:33
Message-ID: 4136ffa0903311053x6f80e0bbl384167a71005aece@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Mar 31, 2009 at 6:44 PM, justin <justin(at)emproshunts(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message justin 2009-03-31 18:19:56 Re: string_to_array with empty input
Previous Message Joshua D. Drake 2009-03-31 17:50:44 Pg Conference East: Registration closing

Browse pgsql-hackers by date

  From Date Subject
Next Message justin 2009-03-31 18:19:56 Re: string_to_array with empty input
Previous Message justin 2009-03-31 17:44:19 Re: string_to_array with empty input