Standard library

The standard library currently contains commonly used functions that are used in SQL. It’s not yet as broad as we’d like, and we’re very open to expanding it.

Currently s-strings are an escape-hatch for any function that isn’t in our standard library. If we find ourselves using them for something frequently, raise an issue and we’ll add it to the stdlib.

Note

Currently the stdlib implementation doesn’t support different DB implementations itself; those need to be built deeper into the compiler. We’ll resolve this at some point. Until then, we’ll only add functions here that are broadly supported by most DBs.

Here’s the source of the current PRQL std:

And a couple of examples:

PRQL

  1. from employees
  2. derive [
  3. gross_salary = (salary + payroll_tax | as int),
  4. gross_salary_rounded = (gross_salary | round 0),
  5. time = s"NOW()", # an s-string, given no `now` function exists in PRQL
  6. ]

SQL

  1. SELECT
  2. *,
  3. CAST(salary + payroll_tax AS int) AS gross_salary,
  4. ROUND(CAST(salary + payroll_tax AS int), 0) AS gross_salary_rounded,
  5. NOW() AS time
  6. FROM
  7. employees