PRQL/prql · error

{}

Error message

{}

What it means

prql_to_sql! delegates to prqlc::compile; if the PRQL source fails to compile (parse or semantic error), the macro panics with the compiler error message. Since the macro runs at compile time, a bad PRQL string becomes a compile error of the Rust crate containing the macro invocation, with the PRQL error text in the panic message.

Solutions

  1. Read the PRQL error in the panic message and fix the query syntax/semantics
  2. Test the query first with `cargo run -p prqlc -- compile query.prql` or the PRQL playground to get better diagnostics
  3. Verify the prqlc version pinned in Cargo.toml supports the syntax used
  4. Temporarily compile at runtime with prqlc::compile to get a Result instead of a panic

Example fix

// before
let sql = prql_to_sql!("from emplyees | take 5");
// after
let sql = prql_to_sql!("from employees | take 5");
Defensive patterns

Strategy: validation

Validate before calling

// Validate PRQL before committing it into the macro
// $ cargo run -q -p prqlc -- compile query.prql

Try / catch

// No catch possible: compile-time panic. Use runtime API to recover:
match prqlc::compile(&prql_string, &opts) {
    Ok(sql) => sql,
    Err(e) => { log::error!("PRQL error: {e}"); fallback_sql }
}

Prevention

When it happens

Trigger: Any syntactically or semantically invalid PRQL passed to prql_to_sql! — typos in transforms, unknown functions, bad types, referencing missing columns, or a version mismatch between macro and intended syntax.

Common situations: Editing an embedded query and introducing a PRQL syntax error; using a PRQL feature unsupported by the pinned prqlc version; copy-pasting SQL that is not valid PRQL.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


AI-assisted analysis of PRQL/prql@e164e249b9 (2026-09-09). Data as JSON: /api/errors/cdf35468ba264e31. Report an issue: GitHub.

Appendix: source

Thrown at prqlc/prqlc-macros/src/lib.rs:32

#[proc_macro]
pub fn prql_to_sql(input: TokenStream) -> TokenStream {
    let input: Expr = syn::parse(input).unwrap();

    let prql_string = match input {
        Expr::Lit(ExprLit {
            lit: Lit::Str(lit_str),
            ..
        }) => lit_str.value(),
        _ => panic!("prql_to_sql! proc macro expected a string"),
    };

    let opts = prqlc::Options::default().no_format().no_signature();

    let sql_string = match prqlc::compile(&prql_string, &opts) {
        Ok(r) => r,
        Err(err) => {
            panic!("{}", err);
        }
    };

    TokenStream::from_iter(vec![TokenTree::Literal(Literal::string(&sql_string))])
}

View on GitHub (pinned to e164e249b9)