Back to Prql

Tuples

web/book/src/reference/syntax/tuples.md

0.13.121.0 KB
Original Source

Tuples

Tuple is a container type, composed of multiple fields. Each field can have a different type. Number of fields and their types must be known at compile time.

Tuple is represented by {}. It can span multiple lines. Fields can be assigned a name. Fields are separated by commas, a trailing comma is optional.

prql
let var1 = {x = 1, y = 2}

let var2 = {           # Span multiple lines
  a = x,
  b = y                # Optional trailing comma
}

let var3 = {
  c,                   # Individual item
  d = b,               # Assignment
}

Tuples are the type of a table row, which means that they are expected by many transforms. Most transforms can also take a single field, which will be converted into a tuple. These are equivalent:

prql
from employees
select {first_name}
prql
from employees
select first_name
<!-- prettier-ignore -->

[!NOTE] Prior to 0.9.0, tuples were previously named Lists, and represented with [] syntax. There may still be references to the old naming.