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:06:03
Message-ID: 4136ffa0903311006v15eb3a25xf3fa94a8ca089fd6@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Tue, Mar 31, 2009 at 5:48 PM, justin <justin(at)emproshunts(dot)com> wrote:
>
> But consider  this fails also
>
> select string_to_array('1, , 3', ',' )::int[] => ERROR:  invalid input
> syntax for integer: " "
>
> yet this works
>
> select string_to_array('1, 2, 3',',')::int[]

Sure, and the analogous pair string_to_array(' ',',')::int[] and
string_to_array('1 ',',')::int[] behave similarly.

The point is that '' could represent no items or one empty string. We
get to pick which one and in any use case where the string was a list
of objects it's almost certainly intended to be an empty list. And
databases are almost always processing lists of things.

I think the only use case where you want it to be a singleton list of
an empty string is when you're doing string parsing such as building a
lexer or something like that, which is isn't a typical use for sql
code.

--
greg

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2009-03-31 17:39:21 Re: [GENEAL] dynamically changing table
Previous Message justin 2009-03-31 16:48:54 Re: [HACKERS] string_to_array with empty input

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2009-03-31 17:10:56 Re: Solaris getopt_long and PostgreSQL
Previous Message Zdenek Kotala 2009-03-31 17:02:34 Re: Solaris getopt_long and PostgreSQL