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'
In almost all situations, a line break acts as a pipe. But there are a few exceptions where a line break doesn’t create a pipeline:
- within a tuple
- within an array
- when the following line is a new statement, which starts with a keyword of
func,letorfrom - Within a line wrap
PRQL
1. from [ # Line break OK in an array
2. {a=2, b=3}
3. ]
4. derive { # Line break OK in a tuple
5. c = 2 * a,
6. }
SQL
1. WITH table_0 AS (
2. SELECT
3. 2 AS a,
4. 3 AS b
5. )
6. SELECT
7. a,
8. b,
9. 2 * a AS c
10. FROM
11. table_0
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
