Pipes

Pipes are the connection between transforms that make up a pipeline. The relation produced by a transform before the pipe is used as the input for the transform following the pipe. A pipe can be represented with either a line break or a pipe character (|).

For example, here the filter transform operates on the result of from employees (which is just the employees table), and the select transform operates on the result of the filter transform.

PRQL

  1. from employees
  2. filter department == "Product"
  3. select {first_name, last_name}

SQL

  1. SELECT
  2. first_name,
  3. last_name
  4. FROM
  5. employees
  6. WHERE
  7. department = 'Product'

In the place of a line break, it’s also possible to use the | character to pipe results between transforms, such that this is equivalent:

PRQL

  1. from employees | filter department == "Product" | select {first_name, last_name}

SQL

  1. SELECT
  2. first_name,
  3. last_name
  4. FROM
  5. employees
  6. WHERE
  7. department = 'Product'

“C’est ne pas un pipe”

In almost all situations, a line break acts as a pipe. But there are a few cases where a line break doesn’t act as a pipe.

  • before or after tuple items
  • before or after list items
  • before a new statement, which starts with let or from (or func)
  • within a line wrap

For example:

PRQL

  1. [
  2. {a=2} # No pipe from line break before & after this list item
  3. ]
  4. derive {
  5. c = 2 * a, # No pipe from line break before & after this tuple item
  6. }

SQL

  1. WITH table_0 AS (
  2. SELECT
  3. 2 AS a
  4. )
  5. SELECT
  6. a,
  7. 2 * a AS c
  8. FROM
  9. table_0

PRQL

  1. let b =
  2. \ 3 # No pipe from line break within this line wrap
  3. # No pipe from line break before this `from` statement
  4. from y
  5. derive a = b

SQL

  1. SELECT
  2. *,
  3. 3 AS a
  4. FROM
  5. y

Inner Transforms

Parentheses are also used for transforms (such as group and window) that pass their result to an “inner transform”. The example below applies the aggregate pipeline to each group of unique title and country values:

PRQL

  1. from employees
  2. group {title, country} (
  3. aggregate {
  4. average salary,
  5. ct = count salary,
  6. }
  7. )

SQL

  1. SELECT
  2. title,
  3. country,
  4. AVG(salary),
  5. COUNT(*) AS ct
  6. FROM
  7. employees
  8. GROUP BY
  9. title,
  10. country