Array
Overview
In Oxla, an array allows you to represent a collection of elements that have the same data type (any built-in data type can be used).
Array Type Declaration
An array type can be declared by appending square brackets to the data type of its elements:
The syntax above allows you to specify the size of the array. However, it does not enforce any limits and the behavior will be the same for arrays of unspecified length. There is also another way to declare an array, by prepending the ARRAY
keyword after the data type of the elements:
Array Values
You can create array literals by using the ARRAY
keyword and combining it with the array’s values enclosed in square brackets and separated by commas:
Such a literal can be used with, e.g. SELECT
or INSERT INTO
statements:
You can also use a string representation of an array as another available option for array’s values syntax. It requires the elements’ values to be enclosed in curly braces and separated by commas:
Such an array value representation can be used in e.g. INSERT INTO
statements with the VALUES
clause:
Any element can be enclosed in double quotes and this is required, if the value contains commas or curly braces:
Accessing Arrays
You can retrieve a single element from an array using the array subscript operator. When it comes to array values indexing, the elements of an n-length array start at index 1
and end at index n
:
NULL
Arrays can also be accessed by using array slices. An array slice is denoted by writing lower_bound:upper_bound
. The bounds can be omitted, in which case the slice is unbounded from a given side:
Limitations
Field Size Limit
In Oxla, the field size limit for variable-size types is 32MB and this limit applies to arrays as well. If a value exceeds the given limit, an error is returned:
Unsupported SQL Clauses
Array columns cannot be used as the key columns in ORDER BY
, GROUP BY
or JOIN
operations. It is also impossible to use the array columns as a part of the index of a table. For all the operations mentioned above, an appropriate error message will be returned:
Arrays can still be used in ORDER BY
or JOIN
operations, if the array column is not the key:
Unsupported SQL Statements
Specific SQL statements currently do not support arrays. These include:
INSERT INTO
withSELECT
: Arrays cannot be directly imported using anINSERT INTO
with aSELECT
statement. Instead, we encourage you to either use theCOPY FROM CSV
command or theINSERT INTO
statement with theVALUES
keywordUPDATE
andDELETE
: Updating or deleting records from a table, which contains array columns is not supportedCOPY TO
: Exporting data from array columns using theCOPY TO
command is not availableCREATE INDEX
: Index on a table cannot be created on an array column.
Any effort to use such operations with arrays will result in an error. For now, these limitations should be considered when designing tables that include array columns.