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

From Brendan Jurd
Subject Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
Date
Msg-id CADxJZo3BicV5ikrVH_GpG1D392y9K11XFs4Npv3P+_fGt_7cPw@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
List pgsql-hackers
On 5 April 2013 13:04, Tom Lane <tgl@sss.pgh.pa.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



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)
Next
From: Tom Lane
Date:
Subject: Re: [PATCH] Exorcise "zero-dimensional" arrays (Was: Re: Should array_length() Return NULL)