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

From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Brendan Jurd <direvus(at)gmail(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>, 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-03-28 01:16:18
Message-ID: CAEZATCWCkTKw7-Cg_smDB7famfE6q6W_VKF_tR8bAh8NAC44JA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 28 March 2013 00:04, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Brendan Jurd <direvus(at)gmail(dot)com> writes:
>> On 28 March 2013 09:39, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>>> Maybe. But even in 1-D, it's still jumping from having one empty array
>>> to infinitely many starting at different indexes, e.g., '{}'::int[] !=
>>> '[4:3]={}'::int[]. There may be a certain logic to that, but I'm not
>>> convinced about its usefulness.
>
>> We already have the ability to define lower bounds other than 1 on
>> arrays, and it would be inconsistent to allow that for arrays with
>> elements, but not for arrays without.
>
> Yeah, if '[1:1]={0}'::int[] is distinct from '[2:2]={0}'::int[],
> it's a bit hard to argue that '[1:0]={}'::int[] must not be
> distinct from '[2:1]={}'::int[]. If we were doing this from scratch
> we might drop the whole notion of nondefault lower bounds, but that
> ship sailed ages ago.
>

You could make the exact same argument for ranges --- if
'[1,1]'::int4range is distinct from '[2,2]'::int4range, why isn't
'[1,1)'::int4range distinct from '[2,2)'::int4range?

I see ranges and arrays as very closely related because the extents of
an array are an integer range, and the extents of an empty array are
an empty range. Moreover, they have almost identical API functions.

There are two internally self-consistent models for handling empty
ranges/arrays --- one in which empty ranges/arrays are considered not
to have lower/upper bounds, and one in which they are. In the first
model, there is only one empty range/array. In the second, there are
infinitely many, all different. Both models can be written in a
consistent way, but what seems inconsistent is to choose one model for
ranges, and change to a different model for arrays.

Regards,
Dean

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2013-03-28 01:18:45 Re: Support for REINDEX CONCURRENTLY
Previous Message Josh Berkus 2013-03-28 01:06:07 Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)