3
Array Type
Array
a set of numbered elements of the same type
one-dimensional, multidimensional
Initialization
usage without an explicit declaration (name-type[])
implicit declaration when creating a base type or a table (_name-type)
Usage
elements as scalar values
array slices
operations on arrays: comparison, inclusion, intersection, concatenation,
usage with ANY or ALL instead of a subquery, etc.
Just like a composite type (a record), an array is not a scalar; it consists of
several elements of another type. But unlike in records, a) all these
elements are of the same type, and b) they are accessed by an integer
index, not by name (here the term index is used in the mathematical sense
of the word, not in the sense of a database index).
An array type does not have to be explicitly declared; it is enough to append
square brackets to the name of the element type. (Besides, when any base
type or a table is created, a new array type is also declared; its name is
derived from the name of the element type by prepending an underscore to
it. But such naming is less intuitive.)
An array is a full-fledged SQL type: you can create table columns of this
type, pass arrays as function parameters, etc. Array elements can be
applied as regular scalar values. Array slices can also be used.
Arrays can be compared and checked for null; you can search arrays for
element inclusion and intersection with other arrays, perform concatenation,
etc. Arrays can also be applied in ANY/SOME and ALL constructs, similar to
subqueries.
You can find various array functions in course handouts.