LinuxCommandLibrary

prqlc

Compile PRQL code into SQL

TLDR

Run the compiler interactively

$ prqlc compile
copy

Compile a specific .prql file to stdout
$ prqlc compile [path/to/file.prql]
copy

Compile a .prql file to a .sql file
$ prqlc compile [path/to/source.prql] [path/to/target.sql]
copy

Compile a query
$ echo "[from employees | filter has_dog | select salary]" | prqlc compile
copy

Watch a directory and compile on file modification
$ prqlc watch [path/to/directory]
copy

SYNOPSIS

General Usage:
prqlc <SUBCOMMAND> [OPTIONS] [ARGS]

Common Usage (Compile):
prqlc compile [OPTIONS] [INPUT_FILE]
(If INPUT_FILE is omitted, reads from stdin. Output defaults to stdout.)

PARAMETERS

<INPUT_FILE>
    The path to the PRQL source file to be compiled. If not provided, prqlc reads the PRQL query from standard input (stdin).

-e, --entry <entry>
    Specifies the entry point (the last pipeline or transform) within the PRQL query that should be compiled to SQL. Useful for multi-pipeline PRQL files.

-f, --format
    Formats the generated SQL output for better readability, applying standard SQL formatting conventions.

-o, --output <output>
    Specifies the path to the output file where the compiled SQL will be written. If not provided, the SQL is written to standard output (stdout).

-t, --target <target>
    Sets the target SQL dialect for compilation. This optimizes the generated SQL for specific database systems. Possible values include: ansi (default), bigquery, clickhouse, duckdb, generic, mysql, postgresql, snowflake, mssql.

--color <color>
    Controls the use of colored output for messages. Possible values: auto (default, uses color if terminal supports it), always, never.

-h, --help
    Displays help information for the prqlc command or a specific subcommand.

-V, --version
    Displays the version information for the prqlc compiler.

DESCRIPTION

prqlc is the command-line interface for the PRQL compiler. PRQL (Pipelined Relational Query Language) is a modern, human-readable language designed to transform and query data, offering a more intuitive and expressive alternative to traditional SQL for many common tasks. Its core philosophy revolves around data pipelines, where data flows through a series of transformations. The `prqlc` tool's primary function is to compile these PRQL queries into standard SQL, making it compatible with virtually any relational database system, from PostgreSQL and MySQL to Snowflake and BigQuery. Beyond compilation, `prqlc` also provides utilities for formatting PRQL code for readability, parsing the PRQL Abstract Syntax Tree, resolving the Relational Query, and debugging compiler issues. This makes it a comprehensive tool for developers and data analysts looking to streamline their data manipulation workflows with a more declarative and readable language.

CAVEATS

PRQL is a relatively new and actively developed language; its feature set and compiler capabilities are continuously evolving, which might lead to changes in syntax or supported SQL constructs. While prqlc aims for broad SQL compatibility, very complex or highly vendor-specific SQL features might not have direct PRQL equivalents or optimal compilation. Users should consult the PRQL documentation for the latest language and compiler features.

SUBCOMMANDS

Beyond the primary compile subcommand, prqlc offers several other functionalities accessible via subcommands:

  • debug: Provides commands for debugging the compiler's internal processes.
  • fmt: Formats PRQL source code according to standard PRQL style guidelines, improving readability.
  • list: Lists available compiler options and targets.
  • parse: Parses a PRQL query and prints its Abstract Syntax Tree (AST), useful for understanding the query's structure.
  • resolve: Resolves a PRQL query and prints its Relational Query (RQ), which is an intermediate representation before SQL generation.

INPUT/OUTPUT FLEXIBILITY

prqlc is designed for flexibility in scripting and command-line piping. It can read PRQL queries from a specified file path or seamlessly from standard input (stdin). Similarly, the compiled SQL output can be directed to a specified file or written to standard output (stdout), allowing for easy integration into shell scripts or automated workflows.

HISTORY

PRQL was conceived in the early 2020s to address the perceived complexities and verbosity of SQL, aiming to provide a more intuitive, pipeline-oriented, and human-readable language for data transformation. The prqlc compiler is the core tool that enables this vision by translating PRQL code into standard SQL, thereby making it compatible with existing relational database infrastructure. Its development has focused on creating a language that is both powerful and easy to use, rapidly gaining adoption within the data community for its innovative approach to querying and transforming data.

SEE ALSO

sqlcmd(1), psql(1), mysql(1), sqlite3(1), jq(1), sed(1), awk(1)

Copied to clipboard