PRQL compiler CLI — prqlc
prqlc serves as a CLI for the PRQL compiler. It is a single, dependency-free binary that compiles PRQL into SQL.
Usage
prqlc compile
This command works as a filter that compiles a PRQL string into an SQL string.
1. $ echo "from employees | filter has_dog | select salary" | prqlc compile
3. SELECT
4. salary
5. FROM
6. employees
7. WHERE
8. has_dog
A PRQL query can be executed with CLI tools compatible with SQL,, such as DuckDB CLI.
1. $ curl -sL https://raw.githubusercontent.com/PRQL/prql/0.8.1/prql-compiler/tests/integration/data/chinook/albums.csv -o albums.csv
2. $ echo "from `albums.csv` | take 3" | prqlc compile | duckdb
3. ┌──────────┬───────────────────────────────────────┬───────────┐
4. │ album_id │ title │ artist_id │
5. │ int64 │ varchar │ int64 │
6. ├──────────┼───────────────────────────────────────┼───────────┤
7. │ 1 │ For Those About To Rock We Salute You │ 1 │
8. │ 2 │ Balls to the Wall │ 2 │
9. │ 3 │ Restless and Wild │ 2 │
10. └──────────┴───────────────────────────────────────┴───────────┘
Executing this command without any argument will start interactive mode, allowing a PRQL query to be written interactively. In this mode, after writing PRQL and press Ctrl-d (Linux, macOS) or Ctrl-z (Windows) to display the compiled SQL.
1. prqlc compile
Just like when using it as a filter, SQL string output can be passed to the DuckDB CLI and similar tools.
1. $ prqlc compile | duckdb
2. Enter PRQL, then press ctrl-d to compile:
4. from `albums.csv`
5. take 3
6. ┌──────────┬───────────────────────────────────────┬───────────┐
7. │ album_id │ title │ artist_id │
8. │ int64 │ varchar │ int64 │
9. ├──────────┼───────────────────────────────────────┼───────────┤
10. │ 1 │ For Those About To Rock We Salute You │ 1 │
11. │ 2 │ Balls to the Wall │ 2 │
12. │ 3 │ Restless and Wild │ 2 │
13. └──────────┴───────────────────────────────────────┴───────────┘
Installation
via Homebrew (macOS, Linux)
1. brew install prqlc
From GitHub release page
Precompiled binaries are available for Linux, macOS, and Windows on the PRQL release page.
From source
1. # From crates.io
2. cargo install prqlc
1. # From a local PRQL repository
2. cargo install --path crates/prqlc
Shell completions
The prqlc shell-completion command prints a shell completion script for supported shells, and saving the printed scripts to files makes for shells to load completions for each session.
Bash
For Linux:
1. prqlc shell-completion bash >/etc/bash_completion.d/prqlc
For macOS:
1. prqlc shell-completion bash >/usr/local/etc/bash_completion.d/prqlc
fish
1. prqlc shell-completion fish >~/.config/fish/completions/prqlc.fish
PowerShell
1. mkdir -Path (Split-Path -Parent $profile) -ErrorAction SilentlyContinue
2. prqlc shell-completion powershell >path/to/prqlc.ps1
3. echo 'Invoke-Expression -Command path/to/prqlc.ps1' >>$profile
zsh
1. prqlc shell-completion zsh >"${fpath[1]}/_prqlc"
Ensure that the following lines are present in ~/.zshrc:
1. autoload -U compinit
2. compinit -i
Helpers
Cheat sheets for prqlc are available on various websites and with various tools.
- tldr (on the web)
- eg

