tursodatabase/turso · error

No SQL in batch step

Error message

No SQL in batch step

What it means

While executing a /v2/pipeline batch, a BatchStep's statement had stmt.sql == None and this server cannot run it: execute_batch_step always prepares SQL by string (conn.prepare(sql)). The wire type makes sql optional (clients may reference previously cached statements), but this implementation has no statement cache and requires SQL text on every step.

Solutions

  1. Set a non-empty sql string on every statement of every batch step before sending
  2. If using a client library, disable statement caching/reuse for sync-server traffic so sql is always included
  3. Validate the outgoing payload: every requests[].stmt.sql must be a non-empty string

Example fix

// before
{"Batch": {"steps": [{"stmt": {"args": [1]}}]}}

// after
{"Batch": {"steps": [{"stmt": {"sql": "INSERT INTO t VALUES (?)", "args": [1]}}]}}
Defensive patterns

Strategy: validation

Validate before calling

for (const step of batch.steps) {
  if (typeof step?.stmt?.sql !== 'string' || step.stmt.sql.trim() === '') {
    throw new Error(`batch step is missing stmt.sql: ${JSON.stringify(step)}`);
  }
}

Type guard

function hasSql(step: unknown): step is { stmt: { sql: string } } {
  return typeof (step as any)?.stmt?.sql === 'string' && (step as any).stmt.sql.length > 0;
}

Prevention

When it happens

Trigger: Sending a batch whose step looks like {"stmt": {"sql": null, "args": [...]}} or that omits the sql key entirely; typically a client relying on prepared-statement reuse the sync server never implemented.

Common situations: Client SDK versions that omit sql for cached statements; hand-built batch JSON where the sql field was dropped when converting an Execute request into a Batch step; integration tests constructing BatchStep structs directly without setting sql.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of tursodatabase/turso@492c4a71cd (2026-08-20). Data as JSON: /api/errors/060a796f219161cb. Report an issue: GitHub.

Appendix: source

Thrown at cli/sync_server.rs:534

            }
            BatchCond::And(list) => list
                .conds
                .iter()
                .all(|c| Self::evaluate_condition(c, step_results, step_errors, conn)),
            BatchCond::Or(list) => list
                .conds
                .iter()
                .any(|c| Self::evaluate_condition(c, step_results, step_errors, conn)),
            BatchCond::IsAutocommit {} => conn.get_auto_commit(),
        }
    }

    fn execute_batch_step(&self, conn: &Arc<Connection>, step: &BatchStep) -> Result<StmtResult> {
        let sql = step
            .stmt
            .sql
            .as_ref()
            .ok_or_else(|| anyhow!("No SQL in batch step"))?;

        debug!("Executing batch step SQL: {}", sql);

        let mut stmt = conn.prepare(sql)?;

        for (i, arg) in step.stmt.args.iter().enumerate() {
            let core_value = convert_value_to_core(arg);
            stmt.bind_at(std::num::NonZero::new(i + 1).unwrap(), core_value)?;
        }

        let want_rows = step.stmt.want_rows.unwrap_or(true);

        if want_rows {
            let rows = stmt.run_collect_rows()?;

            let cols: Vec<Col> = (0..stmt.num_columns())
                .map(|i| Col {
                    name: Some(stmt.get_column_name(i).to_string()),

View on GitHub (pinned to 492c4a71cd)