Sets a script-scoped parameter. The expression is captured as raw SQL text and re-evaluated each time the parameter is referenced.
SET $<name> = <expression>
## Overview SET binds a script parameter to an expression. Subsequent statements in the same script reference the parameter as `$<name>`; the parser substitutes occurrences before executing each statement. ## Behavior - The right-hand side is collected as raw SQL text up to the next semicolon at paren depth zero. Nested parentheses are honored so `(SELECT max(id) FROM t)` is captured whole. - The captured text is re-parsed and evaluated each time `$<name>` is substituted. The evaluation context is the standard expression evaluator used by pipeline DEFAULTS and similar surfaces. - The scope is the current script (session) only. Setting the same parameter twice is allowed; the most recent assignment wins. - Parameters seeded externally (for example via the script-execution API's `ScriptParams.values`) are visible in the same namespace. SET overrides those bindings. - The parameter name must not collide with the special INTO capture mechanism. `... INTO $v1` is a separate construct that captures a query result into a parameter; both pathways write to the same param map. - Substitution is textual and happens before parsing. Use ordinary SQL quoting in the expression for string values; the substituted text is interpolated as-is. ## Access Control No specific privilege is required. ## Compatibility DeltaForge extension. The keyword form differs from PostgreSQL's `SET <name> TO <value>` (which sets a configuration variable, not a script parameter).
| Name | Type | Description |
|---|---|---|
name | Specifies the parameter name (without the leading `$`). Must be a valid identifier. | |
expression | Specifies the value expression. Captured as raw SQL text up to the next semicolon, with balanced parentheses respected so scalar subqueries are captured intact. |
-- Bind a literal
SET $batch_size = 1000;
-- Bind a string
SET $env = 'production';
-- Bind a scalar subquery
SET $latest_id = (SELECT max(order_id) FROM orders);
-- Use the param later in the script
SELECT * FROM orders WHERE order_id > $latest_id LIMIT $batch_size;