Target & Version

Target dialect

PRQL allows specifying a target dialect at the top of the query, which allows PRQL to compile to a database-specific SQL flavor.

Examples

PRQL

  1. prql target:sql.postgres
  2. from employees
  3. sort age
  4. take 10

SQL

  1. SELECT
  2. *
  3. FROM
  4. employees
  5. ORDER BY
  6. age
  7. LIMIT
  8. 10

PRQL

  1. prql target:sql.mssql
  2. from employees
  3. sort age
  4. take 10

SQL

  1. SELECT
  2. TOP (10) *
  3. FROM
  4. employees
  5. ORDER BY
  6. age

Dialects

Supported

Supported dialects support all PRQL language features where possible, are tested on every commit, and we’ll endeavor to fix bugs.

  • sql.clickhouse
  • sql.duckdb
  • sql.generic 1
  • sql.mysql
  • sql.postgres
  • sql.sqlite

Unsupported

Unsupported dialects have implementations in the compiler, but are tested minimally or not at all, and may have gaps for some features.

We’re open to contributions to improve our coverage of these, and to adding additional dialects.

  • sql.glaredb
  • sql.mssql
  • sql.ansi
  • sql.bigquery
  • sql.snowflake

Priority of targets

The compile target of a query is defined in the query’s header or as an argument to the compiler. option. The argument to the compiler takes precedence.

For example, the following shell example specifies sql.generic in the query and sql.duckdb in the --target option of the prqlc compile command. In this case, sql.duckdb takes precedence and the SQL output is based on the DuckDB dialect.

  1. echo 'prql target:sql.generic
  2. from foo' | prqlc compile --target sql.duckdb

To use the target described in the query, a special target sql.any can be specified in the compiler option.

  1. echo 'prql target:sql.generic
  2. from foo' | prqlc compile --target sql.any

Version

PRQL allows specifying a version of the language in the PRQL header, like:

PRQL

  1. prql version:"0.10.0"
  2. from employees

SQL

  1. SELECT
  2. *
  3. FROM
  4. employees

This has two roles, one of which is implemented:

  • The compiler will raise an error if the compiler is older than the query version. This prevents confusing errors when queries use newer features of the language but the compiler hasn’t yet been upgraded.
  • The compiler will compile for the major version of the query. This allows the language to evolve without breaking existing queries, or forcing multiple installations of the compiler. This isn’t yet implemented, but is a gating feature for PRQL 1.0.

The version of the compiler currently in use can be called using the special function std.prql_version in PRQL.

PRQL

  1. [{version = prql_version}]

SQL

  1. WITH table_0 AS (
  2. SELECT
  3. '0.10.0' AS version
  4. )
  5. SELECT
  6. version
  7. FROM
  8. table_0

Note

This function std.prql_version may be replaced in the future by something like prql.version.


1: while there’s no “generic” DB to test sql.generic against, we still count it as supported.