Reputation: 927
I'm trying to test for an empty array. I understand the reasoning behind array_length
returing NULL
since it's a 0-dimensional array, but why is array_ndims(array[]::int array)
not 0
, but rather NULL
?
Upvotes: 1
Views: 138
Reputation: 5950
Looks like it will never return 0:
/* Sanity check: does it look like an array at all? */
if (AARR_NDIM(v) <= 0 || AARR_NDIM(v) > MAXDIM)
PG_RETURN_NULL();
You could write your own C function for this, simply change <= 0
into < 0
. As for reasoning behind this, I can't find anything.
Source is in: https://www.postgresql.org/ftp/source/v10.1/ (same thing for 9.6.2, with is what I checked initially)
File: ./src/backend/utils/adt/arrayfuncs.c
Look for simple, 10 line function: array_ndims
Upvotes: 1