Derive

Computes one or more new columns.

derive [{new_name} = {expression}]

Examples

PRQL

from employees
derive gross_salary = salary + payroll_tax

SQL

SELECT
  employees.*,
  salary + payroll_tax AS gross_salary
FROM
  employees

PRQL

from employees
derive [
  gross_salary = salary + payroll_tax,
  gross_cost = gross_salary + benefits_cost
]

SQL

SELECT
  employees.*,
  salary + payroll_tax AS gross_salary,
  salary + payroll_tax + benefits_cost AS gross_cost
FROM
  employees

derive generally computes a column from existing columns, but can also take a literal in which case it can begin a pipeline without a from:

PRQL

derive x = 5

SQL

SELECT
  5 AS x