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: "David E(dot) Wheeler" <david(at)justatheory(dot)com>, "pgsql-hackers(at)postgresql(dot)org Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Should array_length() Return NULL
Date: 2013-03-16 15:25:39
Message-ID: CADxJZo194K4Nk9sg_6s6CEyX0ppUjg_bfOLr35ZfEm0jAuZ2wg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 16 March 2013 09:07, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "David E. Wheeler" <david(at)justatheory(dot)com> writes:
>> This surprised me:
>
>> david=# select array_length('{}'::text[], 1);
>> array_length
>> --------------
>> [null]
>
>> I had expecte dit to retur 0. I might expect NULL for a NULL param, but not one that's defined but has no elements.
>
> The thing is that that syntax creates an array of zero dimensions,
> not one that has 1 dimension and zero elements. So "0" would be
> incorrect.
>

I'm going to ask the question that immediately comes to mind: Is there
anything good at all about being able to define a zero-dimensional
array?

I would have thought that anything deserving the name "array" has
one-or-more dimensions, and that a "zero-dimensional array" is a weird
way of talking about a scalar value. In which case '{}'::text[] would
not be a legitimate way to declare one anyway. Am I missing
something?

Cheers,
BJ

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2013-03-16 15:35:54 Re: Support for REINDEX CONCURRENTLY
Previous Message Pavel Stehule 2013-03-16 04:56:10 Re: Improving avg performance for numeric