Specifying Subscript Ranges

From InterBase

Go Up to Creating Arrays


In InterBase, array dimensions have a specific range of upper and lower boundaries, called subscripts. In many cases, the subscript range is implicit: the first element of the array is element 1, the second element 2, and the last is element <n>. For example, the following statement creates a table with a column that is an array of four integers:

EXEC SQL
CREATE TABLE TABLE1
(
INT_ARR INTEGER[4]
);

The subscripts for this array are 1, 2, 3, and 4.

A different set of upper and lower boundaries for each array dimension can be explicitly defined when an array column is created. For example, C programmers, familiar with arrays that start with a lower subscript boundary of zero, may want to create array columns with a lower boundary of zero as well.

To specify array subscripts for an array dimension, both the lower and upper boundaries of the dimension must be specified using the following syntax:

lower:upper

For example, the following statement creates a table with a single-dimension array column of four elements where the lower boundary is 0 and the upper boundary is 3:

EXEC SQL
CREATE TABLE TABLE1
(
INT_ARR INTEGER[0:3]
);

The subscripts for this array are 0, 1, 2, and 3.

When creating multi-dimensional arrays with explicit array boundaries, separate each set of subscripts of a dimension from the next with commas. For example, the following statement creates a table with a two-dimensional array column where each dimension has four elements with boundaries of 0 and 3:

EXEC SQL
CREATE TABLE TABLE1
(
INT_ARR INTEGER[0:3, 0:3]
);

Advance To: