tursodatabase/turso · error
query did not return a row
Error message
query did not return a row
What it means
Returned by fetch_single_i64 when a statement expected to yield exactly one integer row produces zero rows (cli/app.rs:2370). The helper drives run_with_row_callback and collects the first column into an Option; the callback succeeds but never fires, so the Option stays None and this error is built.
Source
Thrown at cli/app.rs:2386
s.replace("''", "'")
}
impl Drop for Limbo {
fn drop(&mut self) {
self.save_history();
unsafe {
ManuallyDrop::drop(&mut self.input_buff);
}
}
}
fn fetch_single_i64(rows: &mut turso_core::Statement) -> anyhow::Result<i64> {
let mut result: Option<i64> = None;
rows.run_with_row_callback(|row| {
result = Some(row.get(0)?);
Ok(())
})?;
result.ok_or_else(|| anyhow!("query did not return a row"))
}
/// Normalize `path?key=val` to `file:path?key=val` so query parameters
/// are parsed as URI options (e.g. `?locking=shared_reads`) instead of
/// being treated as part of the filename.
///
/// Only the *last* `?` that introduces a valid `key=value` query string is
/// treated as the query separator. Earlier `?` characters are
/// percent-encoded (`%3F`) so they remain part of the filename.
/// A trailing `?` with no `key=value` pair is left alone (it is just part
/// of the filename).
fn normalize_db_path(db_file: String) -> String {
if db_file.starts_with("file:") {
return db_file;
}
// Walk from the right to find the last '?' whose suffix looks like
// query parameters (contains at least one '=').View on GitHub (pinned to 492c4a71cd)
Solutions
- Run the exact query in the shell - if it returns no rows, fix the query or the data
- For genuinely optional values, map the zero-row case to a default instead of propagating the error
- Verify the PRAGMA or statement is supported and returns a row in this Turso version
Example fix
// before
let n: i64 = fetch_single_i64(&mut stmt)?; // errors on empty result
// after
let n: i64 = match fetch_single_i64(&mut stmt) {
Ok(n) => n,
Err(e) if e.to_string().contains("did not return a row") => 0,
Err(e) => return Err(e),
}; Defensive patterns
Strategy: validation
Validate before calling
let n: i64 = match fetch_single_i64(&mut stmt) {
Ok(n) => n,
Err(e) if e.to_string().contains("did not return a row") => 0,
Err(e) => return Err(e),
}; Prevention
- Decide up front whether zero rows is an error or a default for each lookup
- Test single-value queries against empty databases
- Prefer an Option-returning variant for genuinely optional values
When it happens
Trigger: Calling fetch_single_i64 on a query with an empty result set: a PRAGMA that returns no rows in the current engine state, a WHERE clause filtering everything out, or a metadata query whose row output depends on engine version.
Common situations: PRAGMAs whose output shape changed between versions; single-row lookups against empty tables; predicates that stop matching after data changes.
Related errors
- Error querying database: {}
- Failed to read manual page: {}
- Manual page not found: {page_name}
- Could not determine home directory
- Error setting Ctrl-C handler
AI-assisted analysis of tursodatabase/turso@492c4a71cd (2026-08-20).
Data as JSON: /api/errors/0ba6ade468ce9c27.
Report an issue: GitHub.