Re: Should array_length() Return NULL

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David E(dot) Wheeler" <david(at)justatheory(dot)com>
Cc: "pgsql-hackers(at)postgresql(dot)org Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Should array_length() Return NULL
Date: 2013-03-15 22:07:17
Message-ID: 413.1363385237@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"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.

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2013-03-15 22:08:37 Re: Should array_length() Return NULL
Previous Message Tom Lane 2013-03-15 22:00:21 Re: in-catalog Extension Scripts and Control parameters (templates?)