Search
ctrl/
Ask AI
Light
Dark
System

Tuples

A tuple type is a heterogeneous sequence of other types. Tuples can be either named or unnamed (the default).

A tuple constructor is an expression that consists of a sequence of comma-separated expressions enclosed in parentheses. It produces a tuple value:

"(" expr [, ... ] ")"

Declare a named tuple:

"(" identifier := expr [, ... ] ")"

All elements in a named tuple must have a name.

A tuple constructor automatically creates a corresponding tuple type.

An element of a tuple can be referenced in the form:

expr.element-index

Here, expr is any expression that has a tuple type, and element-index is either the zero-based index of the element or the name of an element in a named tuple.

Examples:

Copy
db> 
select (1, 'EdgeDB').0;
{1}
Copy
db> 
select (number := 1, name := 'EdgeDB').name;
{"EdgeDB"}
Copy
db> 
select (number := 1, name := 'EdgeDB').1;
{"EdgeDB"}

Tuples can be nested:

Copy
db> 
select (nested_tuple := (1, 2)).nested_tuple.0;
{1}

Referencing a non-existent tuple element will result in an error:

Copy
db> 
select (1, 2).5;
EdgeQLError: 5 is not a member of a tuple

---- query context ----

    line 1
        > select (1, 2).3;

A tuple type can be explicitly declared in an expression or schema declaration using the following syntax:

tuple "<" element-type, [element-type, ...] ">"

A named tuple:

tuple "<" element-name : element-type [, ... ] ">"

Any type can be used as a tuple element type.

Here’s an example of using this syntax in a schema definition:

Copy
type GameElement {
    required name: str;
    required position: tuple<x: int64, y: int64>;
}

Here’s a few examples of using tuple types in EdgeQL queries:

Copy
db> 
select <tuple<int64, str>>('1', 3);
{(1, '3')}
Copy
db> 
select <tuple<x: int64, y: int64>>(1, 2);
{(x := 1, y := 2)}
Copy
db> 
select (1, '3') is (tuple<int64, str>);
{true}
Copy
db> 
select ([1, 2], 'a') is (tuple<array<int64>, str>);
{true}

type

tuple

A tuple type is a heterogeneous sequence of other types.

Tuple elements can optionally have names, in which case the tuple is called a named tuple.

Any type can be used as a tuple element type.

A tuple type is created implicitly when a tuple constructor is used:

Copy
db> 
select ('foo', 42);
{('foo', 42)}

Two tuples are equal if all of their elements are equal and in the same order. Note that element names in named tuples are not significant for comparison:

Copy
db> 
select (1, 2, 3) = (a := 1, b := 2, c := 3);
{true}

The syntax of a tuple type declaration can be found in this section.