PRQL/prql · error · Error

not found in namespace `target` (name: )

Error message

{name} not found in namespace `target` (name: {s:?})

What it means

`Target::from_str` parses a compile-target string (the `target` namespace value). If the string isn't a known SQL dialect name, it raises `Reason::NotFound` with the value and namespace. Targets come from CLI flags, query annotations like `prql target:sql.sqlite`, or config files.

Solutions

  1. Use a supported value like `sql.sqlite`, `sql.postgres`, `sql.mysql`, `sql.duckdb`, `sql.mssql`, `sql.bigquery`, `sql.clickhouse`, `sql.ansi`
  2. Check `prqlc compile --help` / docs for the exact accepted target list
  3. Correct the target line in the .prql file or the CLI/env config

Example fix

// before
prql target:sql.psql
// after
prql target:sql.postgres
Defensive patterns

Strategy: validation

Validate before calling

const VALID_TARGETS = ['sql.ansi','sql.bigquery','sql.clickhouse','sql.duckdb','sql.generic','sql.mssql','sql.mysql','sql.postgres','sql.sqlite']; const ok = (t: string) => VALID_TARGETS.includes(t);

Type guard

function isKnownTarget(t: string): boolean { return VALID_TARGETS.includes(t); }

Try / catch

try { compile(prql, { target }) } catch (e) { if (String(e).includes("not found in namespace `target`")) { target = 'sql.generic'; } else { throw e } }

Prevention

When it happens

Trigger: Setting an unknown target string, e.g. `prql target:sql.postgres13`, `--target sql.mysql8`, or an env/config value that isn't a valid `Dialect` per sqlparser's `Dialect::from_str`.

Common situations: Typos in dialect names (`postgres` vs `postgres`? e.g. `sql.psql`), inventing dialect versions not supported by the underlying sqlparser, stale docs referencing removed dialect names.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at prqlc/prqlc/src/lib.rs:256

        names
    }
}

impl FromStr for Target {
    type Err = Error;

    fn from_str(s: &str) -> Result<Target, Self::Err> {
        if let Some(dialect) = s.strip_prefix("sql.") {
            if dialect == "any" {
                return Ok(Target::Sql(None));
            }

            if let Ok(dialect) = sql::Dialect::from_str(dialect) {
                return Ok(Target::Sql(Some(dialect)));
            }
        }

        Err(Error::new(Reason::NotFound {
            name: format!("{s:?}"),
            namespace: "target".to_string(),
        }))
    }
}

/// Compilation options for SQL backend of the compiler.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Options {
    /// Pass generated SQL string through a formatter that splits it
    /// into multiple lines and prettifies indentation and spacing.
    ///
    /// Defaults to true.
    pub format: bool,

    /// Target and dialect to compile to.
    pub target: Target,

View on GitHub (pinned to e164e249b9)