Re: string_to_array with an empty input string

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Peter Geoghegan <peter(dot)geoghegan86(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Greg Stark <gsstark(at)mit(dot)edu>, Thom Brown <thom(at)linux(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: string_to_array with an empty input string
Date: 2010-08-11 22:06:23
Message-ID: AANLkTikwRHY1tOupBWGTwKkujh0C9rp5pwTB8eMnQLRf@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Aug 11, 2010 at 4:21 PM, Peter Geoghegan
<peter(dot)geoghegan86(at)gmail(dot)com> wrote:
> On 11 August 2010 18:53, Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>>> I think that there's a need for additional built-in array functions,
>>> including one to succinctly test if an array has no elements.
>>
>> What do you propose?  I think the easiest ways to do it right now are:
>>
>> array_length(arr, 1) is null
>>
>> or just using an equality test, like this:
>>
>> arr = '{}'::int[]
>
> What's wrong with something like array_is_empty(anyarray) returns
> boolean? I don't know why we're so apparently averse to creating
> built-in convenience functions. It's quite easy to forget the intent
> of either of those two statements.

Nothing's wrong with it, but the second one seems pretty hard to
forget the intent of... at least to me.

>>> Iterating through an array with plpgsql, for example, is more clunky
>>> than it should be.
>>
>> Really?
>>
>> FOR var IN SELECT UNNEST(arr) LOOP ... END LOOP
>>
>> I mean, doing everything is sort of clunky in PL/pgsql, but this
>> doesn't seem particularly bad as PL/pgsql idioms go.
>
> Right. I agree that many of the idioms are on the clunky side, but I
> think that the fact that my original remarks about iterating over
> arrays generated discussion is a bit telling. unnest() was only
> introduced in PG 8.4.

True... but now we have it.

> Iterating over an array is a simple thing. We should make simple things easy.

I definitely agree that PL/pgsql could be more usable. Or if not,
then some other PL with a better overall design could be more usable.
I am not entirely sure how to create such a thing, however.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-08-11 22:21:02 Re: review: psql: edit function, show function commands patch
Previous Message Mike Fowler 2010-08-11 21:33:30 Re: review: xml_is_well_formed