Array behavior - Mailing list pgsql-general

From Steve Crawford
Subject Array behavior
Date
Msg-id 20021126165502.BE94A103C7@polaris.pinpointresearch.com
Whole thread Raw
List pgsql-general
I have an application that seems an ideal candidate for arrays. A table will
contain a unique key and general info (timestamp, origin, etc.) along with
some collected data (data text[]).

The data collected in a single sample could contain zero or more elements
(strings of up to 32 characters), the number of elements is not known in
advance and, items (elements) can be skipped (though for analysis and data
delivery purposes data[3] in one tuple will always correspond to data[3] in
another tuple).

The current (7.2.3) behavior appears to allow me to insert items with one or
more array elements and query on an element (say data[15]) without worrying
that some of the data may only have 3 elements (Postgres returns an empty
string for data[15] in that case). This works well for me.

Question 1: Is this behavior explicitly documented somewhere and can I expect
this to continue to be the behavior of arrays in the future? I have a strong
preference to write code to specifications and not to "something that I
discovered that turns out to be a future fix on someone's todo list".

Question 2: Is there a Postgres function that returns the number of elements
in an array (or another simple method of determining that information)?

Cheers,
Steve

pgsql-general by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: Migrating DAta from MSSQL to postgre
Next
From: Stephan Szabo
Date:
Subject: Re: pgsql-function called twice in the same second ->