Re: ARRAY_LENGTH() function behavior with empty array

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: otar shavadze <oshavadze(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: ARRAY_LENGTH() function behavior with empty array
Date: 2016-12-02 15:20:31
Message-ID: 28740.1480692031@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

otar shavadze <oshavadze(at)gmail(dot)com> writes:
> SELECT ARRAY_LENGTH('{}'::INT[], 1)
> This returns NULL, not so "dangerous" either way, not would be more
> logically, if array length function will return 0 from empty array,
> instead of NULL ?

Well, the issue is that you're asking about dimension 1 of a
zero-dimensional array, so the answer is indeed undefined, not 0.

A lot of people are not terribly happy with PG's array handling,
but there's enough interconnectedness to the behaviors that it's
hard to change just one thing ... and there's also backwards
compatibility to worry about.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message cen 2016-12-02 15:21:58 Full text search randomly not working for short prefixes?
Previous Message Tom Lane 2016-12-02 15:10:05 Re: R: CachedPlan logs until full disk