Query Stack¶
The Query Stack APIs let you compose multiple SQL operations into an immutable StatementStack and execute them in a single driver call. Each operation preserves the underlying SQLResult/ArrowResult so downstream helpers continue to work without copying data.
Overview¶
The stack system is composed of:
StatementStack– immutable builder with push helpers for execute/execute_many/execute_script/execute_arrowStackOperation– the tuple-like value object stored inside the stack (method, statement, arguments, keyword arguments)StackResult– wraps the driver’s raw result while surfacing stack metadata (rows_affected, warning, error)AsyncDriverAdapterBase.execute_stack/SyncDriverAdapterBase.execute_stack– adapter hooks that select native pipelines or the sequential fallback
StatementStack¶
StackResult¶
- class sqlspec.core.result.StackResult[source]¶
Bases:
objectWrapper for per-operation stack results that surfaces driver results directly.
-
result:
StatementResult|ArrowResult¶
- rows_affected¶
- error¶
- warning¶
- metadata¶
- get_result()[source]¶
Return the underlying driver result.
- Return type:
StatementResult|ArrowResult
- with_error(error)[source]¶
Return a copy of the result that records the provided error.
- Return type:
- classmethod from_sql_result(result)[source]¶
Convert a standard SQLResult into a stack-friendly representation.
- Return type:
- classmethod from_arrow_result(result)[source]¶
Create a stack result from an ArrowResult instance.
- Return type:
-
result:
Driver APIs¶
- async AsyncDriverAdapterBase.execute_stack(stack, *, continue_on_error=False)[source]¶
Execute a StatementStack sequentially using the adapter’s primitives.
- Return type:
Exceptions¶
Usage Highlights¶
Build stacks once and reuse them across requests/tasks.
Call
session.execute_stack(stack, continue_on_error=False)to run fail-fast or setcontinue_on_error=Trueto record per-operation errors.Inspect
StackResult.resultto call helpers likeall(),one(),to_pandas(), orto_arrow().Adapters lists per-adapter capabilities, including whether native pipelines or sequential fallback are used for stacks.