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: Brendan Jurd <direvus(at)gmail(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Merlin Moncure <mmoncure(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Florian Pflug <fgp(at)phlo(dot)org>, Josh Berkus <josh(at)agliodbs(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
Date: 2013-04-05 04:05:22
Message-ID: 21882.1365134722@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Brendan Jurd <direvus(at)gmail(dot)com> writes:
> On 5 April 2013 13:04, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> (There's been a remarkable lack of attention to the question
>> of spec compliance in this thread, btw. Surely the standard has
>> something to say on the matter of zero-length arrays?)

> The language specifically allows for zero elements, and does not
> contemplate multiple dimensions. The specification for the array
> constructor syntax (6.36) and array element reference by subscript
> (6.23) also make it fairly clear that only 1-D arrays were being
> considered.

> I'd say we've already gone way off-menu by having multidims.

Yeah, we knew that. I don't have a problem with seeing multidim arrays
as an extension to the standard though. The point is that the behavior
for the 1-D, default-lower-bound case ought to match the standard.

> While I was in there I noticed CARDINALITY, which would be pretty easy
> to add and would at least provide a more productive way to get the
> "real" length of an array without disrupting existing functionality:

Yeah, that would at least fix the null-result-for-empty-array problem
for that particular functionality. Still, this is ammunition for the
position that null results for empty arrays are just broken.

BTW ... if you check the archives you will find that we had
cardinality() for a short while, and removed it before 8.4 release,
because we couldn't agree on what it ought to return when given a
multi-dimensional array. I'm afraid that issue is still unresolved.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2013-04-05 04:12:31 Re: Why there is a PG_GETARG_UINT32 and PG_RETURN_UINT32?
Previous Message Brendan Jurd 2013-04-05 03:32:17 Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)