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

From Tom Lane
Subject Re: Should array_length() Return NULL
Date
Msg-id 413.1363385237@sss.pgh.pa.us
Whole thread Raw
In response to Should array_length() Return NULL  ("David E. Wheeler" <david@justatheory.com>)
Responses Re: Should array_length() Return NULL  ("David E. Wheeler" <david@justatheory.com>)
Re: Should array_length() Return NULL  (Brendan Jurd <direvus@gmail.com>)
List pgsql-hackers
"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.

Our handling of empty arrays leaves something to be desired, I agree,
but making it more consistent seems like a large task.  Hacking
array_length in isolation will certainly not help.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: in-catalog Extension Scripts and Control parameters (templates?)
Next
From: "David E. Wheeler"
Date:
Subject: Re: Should array_length() Return NULL