Thread: Array functions, array_length behavior given an empty array

Array functions, array_length behavior given an empty array

From
PG Doc comments form
Date:
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/13/functions-array.html
Description:

For whom it may concern,

I'd like to propose an extension for `array_length` function description.

Currently, it does not cover the case of an empty array:

https://www.postgresql.org/docs/13/functions-array.html
Table 9.52. Array Functions. Row 5

The description reads as `Returns the length of the requested array
dimension.`

For me, an expected result for an empty array would be `0`, but it is
`NULL`.
Tested on `PostgreSQL 13.4` with query `SELECT
ARRAY_LENGTH(ARRAY[]::CHARACTER VARYING[],1);`

I believe, such case deserves to be mentioned in the description and/or in
examples.

With best regards,
Oleg Rekin

Re: Array functions, array_length behavior given an empty array

From
Pavel Stehule
Date:
Hi

po 8. 11. 2021 v 13:48 odesílatel PG Doc comments form <noreply@postgresql.org> napsal:
The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/13/functions-array.html
Description:

For whom it may concern,

I'd like to propose an extension for `array_length` function description.

Currently, it does not cover the case of an empty array:

https://www.postgresql.org/docs/13/functions-array.html
Table 9.52. Array Functions. Row 5

The description reads as `Returns the length of the requested array
dimension.`

For me, an expected result for an empty array would be `0`, but it is
`NULL`.
Tested on `PostgreSQL 13.4` with query `SELECT
ARRAY_LENGTH(ARRAY[]::CHARACTER VARYING[],1);`

I believe, such case deserves to be mentioned in the description and/or in
examples.


Use instead function cardinality

Regards

Pavel Stehule

 

With best regards,
Oleg Rekin

Re: Array functions, array_length behavior given an empty array

From
"David G. Johnston"
Date:
On Monday, November 8, 2021, Pavel Stehule <pavel.stehule@gmail.com> wrote:
Hi

po 8. 11. 2021 v 13:48 odesílatel PG Doc comments form <noreply@postgresql.org> napsal:
The following documentation comment has been logged on the website:

I believe, such case deserves to be mentioned in the description and/or in
examples.


Use instead function cardinality

I believe the OP has a point that we could do better with the documentation though.  Especially now that we’ve performed the function table reformatting.

David J.

Re: Array functions, array_length behavior given an empty array

From
Pavel Stehule
Date:


po 8. 11. 2021 v 18:11 odesílatel David G. Johnston <david.g.johnston@gmail.com> napsal:
On Monday, November 8, 2021, Pavel Stehule <pavel.stehule@gmail.com> wrote:
Hi

po 8. 11. 2021 v 13:48 odesílatel PG Doc comments form <noreply@postgresql.org> napsal:
The following documentation comment has been logged on the website:

I believe, such case deserves to be mentioned in the description and/or in
examples.


Use instead function cardinality

I believe the OP has a point that we could do better with the documentation though.  Especially now that we’ve performed the function table reformatting.

+1

Pavel


David J.