Re: 9.3: Empty arrays returned by array_remove()

Lists: pgsql-hackers
From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: 9.3: Empty arrays returned by array_remove()
Date: 2013-05-30 16:52:02
Message-ID: CAEZATCXEuJoj3v9RTYYZ0vMDQ4YmmiaA7s+7u096BVbeimW-eQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Testing 9.3beta, it seems that array_remove() may return an empty 1-d
array whose upper bound is lower than its lower bound. I know that we
discussed allowing this kind of array, but I don't think that
discussion reached any conclusion, other than to agree that the
current empty 0-d array behaviour would be kept in 9.3.

I don't think it's intentional, but the current code in array_remove()
can return something like this:

SELECT array_dims(array_remove(array[1], 1));
array_dims
------------
[1:0]
(1 row)

and so the resulting empty 1-d array won't compare as equal to the
usual 0-d empty array:

SELECT array_remove(array[1], 1) = '{}';
?column?
----------
f
(1 row)

The LHS is effectively '[1:0]={}', but we don't currently allow that
syntax, so I don't think we should be returning it (it wouldn't
survive a dump/restore, for example).

Regards,
Dean


From: Brendan Jurd <direvus(at)gmail(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 9.3: Empty arrays returned by array_remove()
Date: 2013-05-31 07:34:43
Message-ID: CADxJZo0mQgB_AgbHo3a4P4F=vmOF-h1U3xViHAxYCM53MuPF5w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 31 May 2013 02:52, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
> Testing 9.3beta, it seems that array_remove() may return an empty 1-d
> array whose upper bound is lower than its lower bound. I know that we
> discussed allowing this kind of array, but I don't think that
> discussion reached any conclusion, other than to agree that the
> current empty 0-d array behaviour would be kept in 9.3.
>

That's right, zero-D is still the only supported representation of an
empty array, so when array_remove() yields an empty array it ought to
be zero-D. Good catch.

Cheers,
BJ


From: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
To: Brendan Jurd <direvus(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 9.3: Empty arrays returned by array_remove()
Date: 2013-05-31 07:55:49
Message-ID: CAEZATCUOkyz=VszVRVWCWLvJdxRTjKgODMhj-GqX1yEaQNQ7ew@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 31 May 2013 08:34, Brendan Jurd <direvus(at)gmail(dot)com> wrote:
> On 31 May 2013 02:52, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
>> Testing 9.3beta, it seems that array_remove() may return an empty 1-d
>> array whose upper bound is lower than its lower bound. I know that we
>> discussed allowing this kind of array, but I don't think that
>> discussion reached any conclusion, other than to agree that the
>> current empty 0-d array behaviour would be kept in 9.3.
>>
>
> That's right, zero-D is still the only supported representation of an
> empty array, so when array_remove() yields an empty array it ought to
> be zero-D. Good catch.
>

Yeah, that's what I thought. Here's a patch to fix it, plus a new
regression test to confirm that the result is a zero-D array.

Regards,
Dean

Attachment Content-Type Size
array_remove.patch application/octet-stream 1.8 KB

From: Noah Misch <noah(at)leadboat(dot)com>
To: Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>
Cc: Brendan Jurd <direvus(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: 9.3: Empty arrays returned by array_remove()
Date: 2013-06-01 01:57:48
Message-ID: 20130601015748.GA244722@tornado.leadboat.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, May 31, 2013 at 08:55:49AM +0100, Dean Rasheed wrote:
> On 31 May 2013 08:34, Brendan Jurd <direvus(at)gmail(dot)com> wrote:
> > On 31 May 2013 02:52, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> wrote:
> >> Testing 9.3beta, it seems that array_remove() may return an empty 1-d
> >> array whose upper bound is lower than its lower bound. I know that we
> >> discussed allowing this kind of array, but I don't think that
> >> discussion reached any conclusion, other than to agree that the
> >> current empty 0-d array behaviour would be kept in 9.3.
> >
> > That's right, zero-D is still the only supported representation of an
> > empty array, so when array_remove() yields an empty array it ought to
> > be zero-D. Good catch.
>
> Yeah, that's what I thought. Here's a patch to fix it, plus a new
> regression test to confirm that the result is a zero-D array.

Committed. Thanks.

--
Noah Misch
EnterpriseDB http://www.enterprisedb.com