Ranges

Range start..end represents as set of values between start and end, inclusive (greater of equal to start and less than or equal to end).

To express a range that is open on one side, either start or end can be omitted.

Ranges can be used in filters with the in function, with any type of literal, including dates:

PRQL

  1. from events
  2. filter (created_at | in @1776-07-04..@1787-09-17)
  3. filter (magnitude | in 50..100)
  4. derive is_northern = (latitude | in 0..)

SQL

  1. SELECT
  2. *,
  3. latitude >= 0 AS is_northern
  4. FROM
  5. events
  6. WHERE
  7. created_at BETWEEN DATE '1776-07-04' AND DATE '1787-09-17'
  8. AND magnitude BETWEEN 50 AND 100

Ranges can also be used in take:

PRQL

  1. from orders
  2. sort {-value, created_at}
  3. take 101..110

SQL

  1. SELECT
  2. *
  3. FROM
  4. orders
  5. ORDER BY
  6. value DESC,
  7. created_at
  8. LIMIT
  9. 10 OFFSET 100

Note

Half-open ranges are generally less intuitive to read than a simple >= or <= operator.

See also

Roadmap

We’d like to use ranges for other types, such as whether an object is in an array or list literal.