A data type used for storing and accessing multidimensional data. The ARRAY data type can store many values of the same specific data type in a sequential or matrix-like format.
where:
Syntax element … |
Specifies … |
|
SYSUDTLIB. |
the name of the database in which all ARRAY data types are created. |
|
array_type_name |
the name of an ARRAY data type that was created with a CREATE TYPE statement. |
|
attribute
|
appropriate data type attributes. An ARRAY column supports the following attributes: |
|
|
|
|
For details on using data type attributes with ARRAY data types, see: An ARRAY data type column does not support column storage or column constraint attributes. |
The one-dimensional (1-D) ARRAY data type is partially compliant with the ANSI SQL:2011 standard. The 1-D ARRAY type is not compatible with the ANSI standard in the following areas:
The multidimensional (n-D) ARRAY data type is a Teradata extension to the ANSI SQL standard. Teradata Database extends the ANSI SQL:2011 syntax for the 1-D ARRAY type to permit multiple dimensions.
Both 1-D and n-D ARRAY data types store and manage their element values in a way that is compliant with the ANSI SQL:2011 standard.
The 1-D ARRAY type is defined as a variable-length ordered list of values of the same data type. It has a maximum number of values that you specify when you create the ARRAY type. You can access each element value in a 1-D ARRAY type using a numeric index value. For details on referencing an ARRAY element, see “ARRAY Functions and Operators” in SQL Functions, Operators, Expressions, and Predicates.
Teradata Database stores the element values of a 1-D ARRAY sequentially starting with the first element, from left-to-right.
The 1-D ARRAY type is compatible with the VARRAY type provided by Oracle Database except for the following areas:
An n-D ARRAY is a mapping from integer coordinates to an element type. The n-D ARRAY type is defined as a variable-length ordered list of values of the same data type. It has 2-5 dimensions, with a maximum number of values for each dimension, which you specify when you create the ARRAY type.
You define an n-D ARRAY type with a pair of lower and upper boundaries [n:m] for each of its dimensions. Alternatively, you can specify a single value [n] to signify the maximum size of a dimension, which implicitly defines the lower bound of the dimension to be 1. For details, see “Creating an ARRAY Data Type” on page 255.
You can access each element value in an n-D ARRAY type using numeric index values for each dimension. For details on referencing an ARRAY element, see “ARRAY Functions and Operators” in SQL Functions, Operators, Expressions, and Predicates.
The figure below shows the constituents of a 3-D ARRAY data type.
Teradata Database stores the element values of an n-D ARRAY in row-major order. Row-major means that the first dimension, which is leftmost in the scope specification, is the most major dimension, and as you move toward the last dimension, the dimensions become less and less major.
An ARRAY data type is a UDT, which means that Teradata Database will store any ARRAY type that you create in the SYSUDTLIB database along with its autogenerated constructor UDF, by default. Therefore, in order to create an ARRAY data type, you must have either the UDTTYPE or UDTMETHOD privilege on the SYSUDTLIB database.
Before you can use an ARRAY data type, you must first create it using the CREATE TYPE statement. When creating a new ARRAY type, you must specify:
For a 1-D ARRAY type, you also specify a maximum number of elements in the ARRAY.
For an n-D ARRAY type, you specify the number of dimensions from 2 to 5, with a pair of lower and upper boundaries for each dimension. You can specify the array boundary dimensions using any combination of the following two methods:
If you specify the optional DEFAULT NULL clause when creating the ARRAY type, all elements are set to NULL when an instance of the ARRAY type is constructed. Otherwise, all elements are set to an uninitialized state. You will receive an error if you try to access an element that is in an uninitialized state.
For detailed information, see “CREATE TYPE (ARRAY Form)” in SQL Data Definition Language.
The data type of an ARRAY element can be any Teradata data type except for the following:
Note that you cannot specify an ARRAY data type as the element type of an ARRAY type.
The following online HELP statement lists all of the valid element data types for an ARRAY data type:
HELP 'array_data_type declarations';
Notice:
KANJI1 support is deprecated. KANJI1 is not allowed as a default character set. The system changes the KANJI1 default character set to the UNICODE character set. Creation of new KANJI1 objects is highly restricted. Although many KANJI1 queries and applications may continue to operate, sites using KANJI1 should convert to another character set as soon as possible.
Teradata Database automatically generates the following routines for each ARRAY data type you create.
Autogenerated Routine |
Description |
Constructor function |
Allocates an ARRAY type instance and sets all the elements to an uninitialized state if the DEFAULT NULL clause was not specified. If DEFAULT NULL was specified, all elements are set to null. |
Constructor method |
Takes one or more arguments and initializes each element of the array with the corresponding value passed to the method. |
Use the ARRAY constructor expression to create a new instance of an ARRAY data type and initialize it using the autogenerated constructor method or function. For details about the ARRAY constructor expression, see “ARRAY Functions and Operators” in SQL Functions, Operators, Expressions, and Predicates.
Teradata Database automatically generates the following functionality for each ARRAY data type you create.
Autogenerated Functionality |
Description |
ARRAY type transform |
from-sql and to-sql functionality associated with the transform of an ARRAY type. The ARRAY values are transformed to/from a VARCHAR(length) value, where length depends on the element type and the total number of elements defined in the ARRAY. For detailed information about transform input/output strings for ARRAY types, see Appendix B: “External Representations for UDTs.” |
ARRAY type ordering |
Basic ordering functionality for an ARRAY type. |
ARRAY type cast |
Casting functionality for an ARRAY type. Two autogenerated casts are provided: VARCHAR to ARRAY, and ARRAY to VARCHAR. |
For detailed information, see “CREATE TYPE (ARRAY Form)” in SQL Data Definition Language.
Note that the size of the array is influenced not only by the number of elements, but also by the element type of the array.
This clause is particularly useful for ARRAY types that are expected to be fully populated.
When you use this clause, the action prevents all subset operations such as AVERAGE, UPDATE, or COUNT for arrays from aborting and returning an error because they refer to an element that is not initialized.
Teradata Database provides system functions, operators, and expressions that operate on either 1-D, n-D, or both ARRAY data types. These functions allow you to perform arithmetic, relational, and aggregate operations on an array in its entirety or on a subset of the elements composing the array. For information about these functions, see “ARRAY Functions and Operators” in SQL Functions, Operators, Expressions, and Predicates.
The following statement uses Teradata syntax to create a 1-D ARRAY type with 5 elements of type CHAR(10). All elements of the array are initialized to null.
CREATE TYPE phonenumbers_ary AS CHAR(10) ARRAY[5] DEFAULT NULL;
The following statement uses Oracle-compatible syntax to create a 1-D ARRAY type with 5 elements of type CHAR(10). All elements of the array are set to an uninitialized state.
CREATE TYPE phonenumbers_ary AS VARRAY(5) OF CHAR(10);
Consider the following structured UDT:
CREATE TYPE measures_UDT AS(amplitude INTEGER,
phase INTEGER,
frequency INTEGER);
The following statement uses Teradata syntax to create a 3-D ARRAY type with elements of type measures_UDT. The scope of this array is composed of three dimensions:
CREATE TYPE seismic_cube AS measures_UDT ARRAY [1:5][1:7][1:20];
The following statement uses Oracle-compatible syntax to create the same 3-D ARRAY type.
CREATE TYPE seismic_cube AS VARRAY (1:5)(1:7)(1:20) OF measures_UDT;
Consider the following 1-D ARRAY type:
CREATE TYPE phonenumbers_ary AS CHAR(10) ARRAY[5] DEFAULT NULL;
The following statement creates a table with a column named ephone that has a data type of phonenumbers_ary, which is a 1-D ARRAY type.
CREATE TABLE my_table (eno INTEGER, ephone phonenumbers_ary);
FOR information on … |
SEE … |
creating an ARRAY data type |
“CREATE TYPE (ARRAY Form)” in SQL Data Definition Language. |
creating a new instance of an ARRAY data type and initializing it |
“ARRAY Functions and Operators” in SQL Functions, Operators, Expressions, and Predicates. |
accessing the element values of an ARRAY data type |
“ARRAY Functions and Operators” in SQL Functions, Operators, Expressions, and Predicates. |
system functions, operators, and expressions that operate on ARRAY data types |
“ARRAY Functions and Operators” in SQL Functions, Operators, Expressions, and Predicates. |
writing routines that use ARRAY input and output parameters |
SQL External Routine Programming. |
transform input/output strings for ARRAY types |