Skip to content

Tuple functions ​

Tuple functions construct a record and read one of its fields. Each tuple has a fixed field count, and a typed tuple can declare a different type for every field.

tuple ​

text
tuple(value1, ...)

Constructs a nonempty positional tuple from its arguments. To assign field names or enforce exact field types, use a Tuple declaration or cast.

tuple_element ​

text
tuple_element(value, position)
tuple_element(value, 'field_name')

A position is positive and one-based, and must fit the tuple's declared field count. A name is case-sensitive and must identify a named field. The selected field retains its native type.

Examples ​

Positional access ​

sql
SELECT tuple_element(tuple(7, 'Ada'), 1),
       tuple_element(tuple(7, 'Ada'), 2)
FORMAT csv;
text
7,"Ada"

Named access ​

sql
SELECT tuple_element(
    CAST('{"id":7,"name":"Ada"}' AS Tuple(id UInt64, name String)),
    'name'
)
FORMAT csv;
text
"Ada"

Named tuple columns also support dotted access, such as profile.name. get_subcolumn can select a named path. See Tuple for input shape and nullable field rules.