Arrays: null values beyond end of array - Mailing list pgsql-general

From Steve Crawford
Subject Arrays: null values beyond end of array
Date
Msg-id 20021203210136.B13CD103C2@polaris.pinpointresearch.com
Whole thread Raw
List 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 by date:

Previous
From: Oskar Berggren
Date:
Subject: Re: Get list of tables in a database
Next
From: Bruno Wolff III
Date:
Subject: Re: Postgresql -- initial impressions and comments