Specifying Subscript Ranges for Array Dimensions

From InterBase
Jump to: navigation, search

Go Up to Defining 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, might 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 the set of subscripts of each 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: