Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)

From: Brendan Jurd <direvus(at)gmail(dot)com>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Josh Berkus <josh(at)agliodbs(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
Date: 2013-06-13 03:00:51
Message-ID: CADxJZo2=WuJhqGTN0PbnKvAcfXZQgOb80nmU9F2watUGO3rmqQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 13 June 2013 04:26, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Wed, Jun 12, 2013 at 1:20 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Josh Berkus <josh(at)agliodbs(dot)com> writes:
>>> On 06/12/2013 11:01 AM, Tom Lane wrote:
>>>> I'm going to be disappointed if all we can get out of this is
>>>> a cardinality() function, and nothing is done about the empty-array
>>>> semantics.

I would be disappointed too, but on the other hand, CARDINALITY is
required by the spec and anything would be better than nothing.

>> Meh. Robert was pretty vocal about it, but it wasn't clear to me that
>> his was the majority opinion, and in any case there wasn't much
>> consideration given to compromises falling somewhere between "no
>> changes" and the rather drastic solution Brendan proposed.

I'm all for looking into possible compromises, and will happily take
any improvements to this mess I think I can get past the compatibility
maximalist caucus.

>> regression=# select array_dims('{}'::int[]) is null;
>> ?column?
>> ----------
>> t
>> (1 row)
>>
>> Whatever you think the dimensions of that are, surely they're not
>> unknown.

I don't think anyone has actually tried to defend the behaviour of the
array functions w.r.t. empty arrays. Even the opponents of the
original proposal agreed that the behaviour was silly, they just
didn't want to fix it, on account of the upgrade burden.

> But, couldn't that be solved by deprecating that function and
> providing a more sensible alternatively named version?

And what would you name that function? array_dims2? I can't think of
a name that makes the difference in behaviour apparent. Can you
imagine the documentation for that?

array_dims - Returns the dimensions of the array, unless it is empty
in which case NULL.
array_proper_dims - Returns the dimensions of the array.
array_ndims - Returns the number of dimension, unless it is empty in
which case NULL.
array_proper_ndims - Returns the number of dimensions.

... and so on for _length, _upper and _lower.

Cheers,
BJ

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2013-06-13 03:12:16 [PATCH] Add session_preload_libraries configuration parameter
Previous Message Tom Dunstan 2013-06-13 02:35:52 Re: Patch to add support of "IF NOT EXISTS" to others "CREATE" statements