# SQL Where a service runs a SQL statement from a definition (for example pipeline `silver.transform.sql_query`), it lists that path in the context's `sql` paths. Each placeholder there becomes a SQL literal, never raw text (§8.3): ```python ctx = Context.from_values( {"tenant_id": t, "run": run, "variables": variables, "transform": transform}, sql=["transform.sql_query"], ) sql = ctx.resolve("transform.sql_query") # SELECT * FROM bronze WHERE fiscal_year = 2026 AND job = 'c3333333-…' ``` The library cannot tell SQL from other text: a SQL path that is not listed is resolved as plain text, values spliced in as they are. List every one. The value at a SQL path must be a string (`type` otherwise). ## Literals | Value | Literal | | --- | --- | | string | `'…'`, each `'` doubled: `O'Brien` → `'O''Brien'` | | integer, float | the number; a negative one in parentheses: `(-5)` | | boolean | `TRUE` / `FALSE` | | object, array | `type` error | The JSON type decides the literal: `2026` gives `2026`, `"2026"` gives `'2026'`. Negative numbers are parenthesised so `x -@{n}` can never turn into a `--` comment. ## Where a placeholder may stand A placeholder must stand where a SQL literal can stand. These fail with `sql_position`: | SQL | Why | | --- | --- | | `WHERE a = '@{x}'` | inside a string (also `E'…'`, `$$…$$`, `$tag$…$tag$`) | | `SELECT "col_@{x}"` | inside a quoted identifier | | `-- @{x}`, `/* @{x} */` | inside a comment | | `col@{x}`, `@{x}abc`, `1.@{x}` | glued to an identifier, number, or `.` | | `@{a}@{b}` | two placeholders glued together | The lexer follows the Postgres rules DuckDB uses (nested block comments, non-ASCII dollar-quote tags). Where it cannot tell how DuckDB would read the text, it treats the rest of the statement as quoted, so a later placeholder is rejected rather than guessed at. ## No secrets Secrets never go into SQL. Both fail with `sql_secret`: - a `get_secret` or `secret` call in the statement, nested at any depth (`@{str_join, @{get_secret, …}}`). This is checked before anything is resolved, so the vault is never read; - a value that contains a secret this context has read, such as a variable the service resolved from `get_secret`, or `str_join` over one. Only secrets this context read are known: a value from any namespace that holds a secret read elsewhere passes. Resolve variables with the same context. The match is on the text, like `scrub`'s, so a very short secret also refuses unrelated values that happen to contain it. ## When the checks run `validate` checks a SQL string like any other value: syntax and dialect. Pass the SQL paths with `sql=` and it also reports, from the text alone, a placeholder where no literal can stand (`sql_position`) and a `get_secret` or `secret` call (`sql_secret`): a secret in SQL is a definition error, found before the job is sent. The same checks run when a SQL path is resolved, before any value is read, so a bad statement fails without touching the vault. Then each placeholder is resolved in order: its value is checked for secrets and its literal type as it is rendered, so the first failing placeholder decides the error. A dispatcher must list the same SQL paths in its context as the worker: a `resolve(strict=False)` keeps a SQL path as written (its `lookup` and time calls become SQL literals only in the worker), but a path it does not know is plain text to it, and a value would be spliced in unquoted.