Length returns NULL ?

From: Marcos Pegoraro <marcos(at)f10(dot)com(dot)br>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Length returns NULL ?
Date: 2024-06-05 17:50:26
Message-ID: CAB-JLwZmKYDT=0WSkvKHLqaejxWoMjBok3YjUtAtM1U8=N__0g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

There are some functions called ...length, but only array_length returns
NULL on empty array, why ?

select array_length('{}'::text[],1), -->NULL
jsonb_array_length('[]'), -->0
bit_length(''), -->0
octet_length(''), -->0
length(''), -->0
char_length(''), -->0
length(B''); -->0

I know, it is documented, but the question is, why does it work differently
?

array_length ( anyarray, integer ) → integer
Returns the length of the requested array dimension. (Produces NULL instead
of 0 for empty or missing array dimensions.)

array_length(array[1,2,3], 1) → 3
array_length(array[]::int[], 1) → NULL
array_length(array['text'], 2) → NULL

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Erik Wienhold 2024-06-05 19:07:52 Re: Length returns NULL ?
Previous Message Adrian Klaver 2024-06-05 15:01:30 Re: Variant (Untyped) parameter for function/procedure