Re: doc: array_length produces null instead of 0

Поиск
Список
Период
Сортировка
От Aleksander Alekseev
Тема Re: doc: array_length produces null instead of 0
Дата
Msg-id CAJ7c6TN2AvpsWg5_Mqx39Kw-YeRZbZzojKX6BVJPz-UXPP_G3Q@mail.gmail.com
обсуждение исходный текст
Ответ на doc: array_length produces null instead of 0  ("David G. Johnston" <david.g.johnston@gmail.com>)
Ответы Re: doc: array_length produces null instead of 0  ("David G. Johnston" <david.g.johnston@gmail.com>)
Compilation issue on Solaris.  (Ibrar Ahmed <ibrar.ahmad@gmail.com>)
Список pgsql-hackers
Hi David,

> Per discussion here:
>
> https://www.postgresql.org/message-id/163636931138.8076.5140809232053731248%40wrigleys.postgresql.org
>
> We can now easily document the array_length behavior of returning null instead of zero for an empty array/dimension.
>
> I added an example to the json_array_length function to demonstrate that it does return 0 as one would expect, but
contraryto the SQL array behavior.
 
>
> I did not bother to add examples to the other half dozen or so "_length" functions that all produce 0 as expected.
Justthe surprising case and the adjacent one.
 

Good catch.

+        <literal>array_length(array[], 1)</literal>
+        <returnvalue>NULL</returnvalue>

One tiny nitpick I have is that this example will not work if used
literally, as is:

```
=# select array_length(array[], 1);
ERROR:  cannot determine type of empty array
LINE 1: select array_length(array[], 1);
```

Maybe it's worth using `array_length(array[] :: int[], 1)` instead.

-- 
Best regards,
Aleksander Alekseev



В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Jonathan S. Katz"
Дата:
Сообщение: PostgreSQL 15 Beta 2 release
Следующее
От: Przemysław Sztoch
Дата:
Сообщение: Re: [PATCH] Completed unaccent dictionary with many missing characters