Re: array_ndims never returns zero

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Vladimir Svedov <vodevsh(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: array_ndims never returns zero
Date: 2017-12-29 17:50:59
Message-ID: CAFj8pRCiJwJMZcHJTJFXsNwDZS4JNvza5_zpxsxWOaj+zy3SPA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2017-12-29 17:52 GMT+01:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:

> Vladimir Svedov <vodevsh(at)gmail(dot)com> writes:
> > Reading
> > https://stackoverflow.com/questions/48022753/why-does-
> array-ndimsarray-produce-null#48022980
> > confused me much - why array_ndims never returns zero indeed?..
>
> Yeah, it's not a very good choice that it returns null for a zero-D
> array. But it's been like that for 20-some years, so the question
> is whether we are prepared to take the compatibility hit from
> changing it.
>
> If we were willing to break things around zero-D arrays, I don't think
> that's the only thing to change. It's equally silly that array_dims()
> returns NULL for such arrays, for instance; their dimensions are
> certainly not unknown. Perhaps an empty string is the right result,
> though I've not thought about it hard.
>
> I'd also argue that an out-of-range AARR_NDIM result is grounds
> for raising an error; returning NULL is a poor substitute for
> reporting data corruption.
>
> In short, if we're to touch this, I'd want somebody to go through all
> the array functions/operators and see if anything else is weird with
> zero-D arrays.
>

Although I see a cost of compatibility break, I agree so NULL in this case
is confusing.

The empty array can be taken as possible unlimited dimensional with zero
sized dimensions.

The test on zero is more readable.

Regards

Pavel

>
> regards, tom lane
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Alvaro Herrera 2017-12-29 17:59:30 Re: [HACKERS] Proposal: Local indexes for partitioned table
Previous Message Pavel Stehule 2017-12-29 17:42:13 Re: Converting plpgsql to use DTYPE_REC for named composite types