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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
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 03:01:15
Message-ID: 13056.1364439675@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> writes:
> On 28 March 2013 00:04, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> 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[].

> 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?

Because an array's bounds are a core piece of the identity of the
array. In another universe PG's arrays might not have been defined
like that, but as things stand, they are. We chose to define ranges
differently. That's okay, because ranges *are not arrays*. If they
were the same, we'd not have needed to invent a separate concept.

> 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.

I think this argument has about as much validity as claiming that
because the subscripts of an array are integers, arrays should behave
like integers.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Konstantin Izmailov 2013-03-28 05:03:01 Re: [HACKERS] money with 4 digits after dot
Previous Message Andrew Dunstan 2013-03-28 02:16:22 Re: JSON Function Bike Shedding