Statements & Stack¶
from sqlspec.core import (
SQL,
ExplainFormat,
ExplainOptions,
ProcessedState,
StackExecutionMetrics,
StackOperation,
Statement,
StatementConfig,
StatementStack,
get_default_config,
get_default_parameter_config,
)
SQL statement encapsulation, dialect configuration, batched StatementStack pipelines, and EXPLAIN options. See Querying and Transactions for usage examples.
Statement & Configuration¶
SQL
¶
SQL statement with parameter and filter support.
Represents a SQL statement that can be compiled with parameters and filters. Supports both positional and named parameters, statement filtering, and various execution modes including batch operations.
compile
¶
Compile SQL statement with parameters.
Returns:
| Type | Description |
|---|---|
tuple[str, Any]
|
Tuple of compiled SQL string and execution parameters |
StatementConfig
¶
Configuration for SQL statement processing.
Controls SQL parsing, validation, transformations, parameter handling, and other processing options for SQL statements.
ProcessedState
¶
Processing results for SQL statements.
Contains the compiled SQL, execution parameters, parsed expression, operation type, and validation errors for a processed SQL statement.
get_default_config
¶
Get default statement configuration.
Returns:
| Type | Description |
|---|---|
StatementConfig
|
Cached StatementConfig singleton with default settings. |
get_default_parameter_config
¶
Get default parameter configuration.
Returns:
| Type | Description |
|---|---|
ParameterStyleConfig
|
ParameterStyleConfig with QMARK style as default |
Statement Stacks¶
StatementStack
¶
StackOperation
¶
Single SQL operation captured inside a statement stack.
StackExecutionMetrics
¶
Capture telemetry facts about a stack execution.
Explain Options¶
ExplainOptions
¶
Configuration options for EXPLAIN statements.
Encapsulates all possible EXPLAIN options across different database dialects. Not all options are supported by all databases - the builder will select appropriate options based on the target dialect.
SQLite
Only supports EXPLAIN QUERY PLAN (no additional options)
DuckDB
analyze: Execute and show actual statistics format: Output format (TEXT, JSON)
Oracle
Uses EXPLAIN PLAN FOR + DBMS_XPLAN.DISPLAY (special handling)
BigQuery
analyze: Execute and show actual statistics (incurs costs!)