Re: Should array_length() Return NULL - Mailing list pgsql-hackers

From Brendan Jurd
Subject Re: Should array_length() Return NULL
Date
Msg-id CADxJZo194K4Nk9sg_6s6CEyX0ppUjg_bfOLr35ZfEm0jAuZ2wg@mail.gmail.com
Whole thread Raw
In response to Re: Should array_length() Return NULL  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Should array_length() Return NULL  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On 16 March 2013 09:07, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> "David E. Wheeler" <david@justatheory.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



pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Improving avg performance for numeric
Next
From: Fujii Masao
Date:
Subject: Re: Support for REINDEX CONCURRENTLY