Arrays: null values beyond end of array

Поиск
Список
Период
Сортировка
От Steve Crawford
Тема Arrays: null values beyond end of array
Дата
Msg-id 20021203210136.B13CD103C2@polaris.pinpointresearch.com
обсуждение исходный текст
Список pgsql-general
The docs say that arrays don't contain SQL nulls. This appears to be true
_within_ the array. Selecting an element beyond the end of the array,
however, does return null and generates no error.

Is the ability to query an array element beyond the end documented somewhere
as legal and is this behavior likely to continue?

This behavior works well for me but I don't want to build an app around it
unless I know it is legal and not just an accidental discovery. My tests:

The data:
steve=# select * from foo;
 id |       bar
----+-----------------
  1 | {one}
  2 | {one,two}
  3 | {one,two,three}
  4 | {"","",""}
 (4 rows)

Looking for nulls:
steve=# select id, case when bar[3] is null then 'I am null' else bar[3] end
as bar3 from foo;
 id |   bar3
----+-----------
  1 | I am null
  2 | I am null
  3 | three
  4 |
(4 rows)

Cheers,
Steve

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

Предыдущее
От: Oskar Berggren
Дата:
Сообщение: Re: Get list of tables in a database
Следующее
От: Bruno Wolff III
Дата:
Сообщение: Re: Postgresql -- initial impressions and comments