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 04:46:54
Message-ID: CADxJZo3AJbhkQ2aYOB35oM1CqqoXcYy2RrM7+8moRw+sNtnTWg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 5 April 2013 15:05, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Brendan Jurd <direvus(at)gmail(dot)com> writes:
>> 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.

Well for what it's worth I would expect cardinality() to return the
total number of elements in the array (per ArrayGetNItems). It's
consistent with the spec's identification of an array as a
"collection". You can chunk the elements into dimensions however you
want, but it's still a collection of elements, and the cardinality is
still the number of elements.

The "nesting" interpretation doesn't accord with our internal
representation, nor with our requirement that multidim arrays be
regular, nor with the fact that we can't put an array of texts inside
an array of ints. Our array input syntaxes for multidim arrays look
nest-ish but what they produce is not nested.

Cheers,
BJ

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2013-04-05 05:12:14 Re: Page replacement algorithm in buffer cache
Previous Message Amit Kapila 2013-04-05 04:43:05 Re: Multi-pass planner