> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://ocient.ferndocs.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://ocient.ferndocs.com/_mcp/server.

# Array, Tuple, and Matrix Overview

> Learn how to work with arrays, tuples, and matrices in Ocient, ideal for handling structured and complex data.

Arrays, tuples, and matrix data types are complex data types in the Ocient® System.

## Arrays

The array data type is a one-dimensional list of values with the same data type. This type enables the support of a one-to-many relationship without creating another table. You create secondary indexes on arrays, which index the elements of the array. For details about secondary indexes, see [**Secondary Indexes**](/guides/database-administration/schema-design/secondary-indexes).

Key features:

* Variable size.
* Can contain many elements.
* Indexing into the array starts at `1`.
* Invalid access of the array returns NULL.

For semi-structured data in JSON format, you can express the JSON multi-value column in an array data type. Traditionally in the normalized relational data model, the database represents such data types as a separate table. Each row stores the value of the primary key of the record in the parent table. Therefore, the entity relationship between the tables is always one-to-many, which can result in billions of rows. The array data type eliminates the child tables, which helps reduce the storage footprint and avoids the additional JOIN operations.

**Examples**

Create a one-dimensional integer array `[1, 2, 3]` using the `sys.dummy` virtual table.

```sql
 SELECT INT[](1,2,3)
 FROM sys.dummy1;
```

*Output*

```none
array_int(int((1)), int((2)), int((3)))
--------------------------------------------------------------------------------
[1,2,3]

Fetched 1 row
```

Create a two-dimensional integer array `[[1, 2, 3], [4, 5, 6]]`.

```sql
 SELECT INT[][](INT[](1,2,3),INT[](4,5,6))
 FROM sys.dummy1;
```

*Output*

```none
array_array(int)(array_int(int((1)), int((2)), int((3))), array_int(int((4)), int((5)), int((6))))
---------------------------------------------------------------------------------------------------
[[1,2,3],[4,5,6]]

Fetched 1 row
```

You can get the same result by casting the array and integers explicitly.

```sql
SELECT INT[][](ARRAY[INT(1),INT(2),INT(3)],ARRAY[INT(4),INT(5),INT(6)])
FROM sys.dummy1;
```

For more examples, see [**Array Functions and Operators**](/guides/sql-reference/array-functions-and-operators).

## Tuples

The tuple data type is a row. This type is a fixed-sized collection of heterogeneous values. Tuples support more complex recursive computational functions. The memory structure of the tuple is identical to the memory structure of the array type. The only difference is that each entry in a tuple can be any type, so the Ocient System can simultaneously store both fixed and variable-sized values in a tuple.

**Examples**

Create a tuple with fixed-size types. In this case, use three integers.

```sql
SELECT TUPLE(1,2,3)
FROM sys.dummy1;
```

*Output*

```none
tuple((1), (2), (3))
--------------------------------------------------------------------------------
<<1, 2, 3>>

Fetched 1 row
```

You can get the same result by using the tuple type constructor.

```sql
SELECT TUPLE<<INT,INT,INT>>(1,2,3)
FROM sys.dummy1;
```

Create a tuple with variable-size types. In this case, use a one-dimensional and two-dimensional array.

```sql
SELECT TUPLE(ARRAY[INT(1),INT(2),INT(3)],
    INT[][](ARRAY[INT(1),INT(2),INT(3)],ARRAY[INT(4),INT(5),INT(6)]))
FROM sys.dummy1;
```

*Output*

```none
tuple(array_int(int((1)), int((2)), int((3))), array_array(int)(array_int(int((1)), int((2)), int((3))), array_int(int((4)), int((5)), int((6)))))
---------------------------------------------------------------------------------------------------------------------------------------------------
<<[1,2,3], [[1,2,3],[4,5,6]]>>

Fetched 1 row
```

Create a tuple with different types. In this case, an integer, string, and array of integers.

```sql
SELECT TUPLE<<INT,VARCHAR,INT[]>>(1, 'test_string', INT[](2,4,6))
FROM sys.dummy1;
```

*Output*

```none
tuple(int((1)), ('test_string'), array_int(int((2)), int((4)), int((6))))
--------------------------------------------------------------------------------
<<1, test_string, [2,4,6]>>

Fetched 1 row
```

For more examples, see [**Tuple Functions and Operators**](/guides/sql-reference/tuple-functions-and-operators).

## Matrixes

A matrix is a fixed-size two-dimensional array of `DOUBLE` values. A matrix can be a row vector (1xN matrix) or column vector (Nx1 matrix).

Matrixes support machine learning model calculations. For details, see [**Machine Learning in Ocient**](/guides/analysis-in-ocient/machine-learning-in-ocient).

**Examples**

Create a 1x4 matrix with numbers 1 through 4 using the `make_matrix` function that expects values in row-major order. The first two arguments indicate the dimensions of the matrix, and the remaining arguments specify the values for the matrix.

```sql
SELECT make_matrix_1x4(1,4,1,2,3,4)
FROM sys.dummy1;
```

*Output*

```none
make_matrix_1x4((1), (4), (1), (2), (3), (4))
--------------------------------------------------------------------------------
[[1.0,2.0,3.0,4.0]]

Fetched 1 row
```

Create a 2x3 matrix with numbers 1 through 6.

```sql
SELECT make_matrix_2x3(2,3,1,2,3,4,5,6)
FROM sys.dummy1;
```

*Output*

```none
make_matrix_2x3((2), (3), (1), (2), (3), (4), (5), (6))
--------------------------------------------------------------------------------
[[1.0,2.0,3.0],[4.0,5.0,6.0]]

Fetched 1 row
```

Create a row vector with four doubles.

```sql
SELECT _R{1,2,3,4}
FROM sys.dummy1;
```

*Output*

```none
_r{1,2,3,4}
--------------------------------------------------------------------------------
[[1.0,2.0,3.0,4.0]]

Fetched 1 row
```

For more examples, see [**Matrix Functions and Operators**](/guides/sql-reference/matrix-functions-and-operators).

## Related Links

[**Array Functions and Operators**](/guides/sql-reference/array-functions-and-operators)

[**Tuple Functions and Operators**](/guides/sql-reference/tuple-functions-and-operators)

[**Matrix Functions and Operators**](/guides/sql-reference/matrix-functions-and-operators)

[**Generate Tables Using sys.dummy**](/guides/query-ocient/general-sql-syntax/generate-tables-using-sys-dummy)