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

From: Brendan Jurd <direvus(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
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 03:32:17
Message-ID: CADxJZo3BicV5ikrVH_GpG1D392y9K11XFs4Npv3P+_fGt_7cPw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

From 4.10 in my draft copy of "Foundation", arrays are one of two
"collection" types (the other being multisets), and:

"A collection is a composite value comprising zero or more elements,
each a value of some data type DT"

"The number of elements in C is the cardinality of C"

"An array is a collection A in which each element is associated with
exactly one ordinal position in A. If n is
the cardinality of A, then the ordinal position p of an element is an
integer in the range 1 (one) ≤ p ≤ n."

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. A more
compliant approach would have been to implement arrays as 1-D only,
and then maybe have a separate thing ("matrices"?) for multidims.

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:

"<cardinality expression> ::=
CARDINALITY <left paren> <collection value expression> <right paren>"

Cheers,
BJ

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-04-05 04:05:22 Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
Previous Message Tom Lane 2013-04-05 02:04:43 Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)