Go Up to Specifying Data Types
InterBase allows you to create arrays of data types. Using an array enables multiple data items to be stored in a single column. InterBase can perform operations on an entire array, effectively treating it as a single element, or it can operate on an array slice, a subset of array elements. An array slice can consist of a single element, or a set of many contiguous elements.
Using an array is appropriate when:
- The data items naturally form a set of the same data type.
- The entire set of data items in a single database column must be represented and controlled as a unit, as opposed to storing each item in a separate column.
- Each item must also be identified and accessed individually.
The data items in an array are called array elements. An array can contain elements of any InterBase data type except
BLOB, and cannot be an array of arrays. All of the elements of a particular array are of the same data type.
Arrays are defined with the
CREATE DOMAIN or
CREATE TABLE statements. Defining an array column is just like defining any other column, except that the array dimensions must also be specified. For example, the following statement defines both a regular character column, and a single-dimension, character array column containing four elements:
EXEC SQL CREATE TABLE TABLE1 (NAME CHAR(10), CHAR_ARR CHAR(10));
Array dimensions are always enclosed in square brackets following a data type specification of a column.
For a complete discussion of
CREATE TABLE and array syntax, see the Language Reference. To learn more about the flexible data access provided by arrays, see the Embedded SQL Guide.