Skip to main content
QueryResult represents the result of any kind of CQL request to the database. It holds response data in a raw binary form, which can be transformed into a typed result for row access.

Overview

QueryResult is returned from query execution methods like query_unpaged() and execute_unpaged(). It represents a single page of results if paging is used. The received rows and metadata are kept in raw binary form. To deserialize and access them, transform QueryResult to QueryRowsResult by calling into_rows_result().
This is the result of a single CQL request. If you use paging, this will contain exactly one page.

Methods

request_coordinator

request_coordinator
fn
Returns the node and shard that served the request.Returns: &CoordinatorExample:
let result = session
    .query_unpaged("SELECT * FROM ks.tab", &[])
    .await?;

let coordinator = result.request_coordinator();
println!("Request served by: {:?}", coordinator);

warnings

warnings
fn
Returns an iterator over warnings emitted by the database during query execution.Returns: impl Iterator<Item = &str>Example:
let result = session
    .query_unpaged("SELECT * FROM ks.tab", &[])
    .await?;

for warning in result.warnings() {
    eprintln!("Warning: {}", warning);
}

tracing_id

tracing_id
fn
Returns the tracing ID associated with this CQL request, if tracing was enabled.Returns: Option<Uuid>Example:
use scylla::statement::unprepared::Statement;

let mut stmt = Statement::new("SELECT * FROM ks.tab");
stmt.set_tracing(true);

let result = session.query_unpaged(stmt, &[]).await?;

if let Some(tracing_id) = result.tracing_id() {
    let tracing_info = session.get_tracing_info(&tracing_id).await?;
    println!("Query took: {:?}", tracing_info.duration);
}

is_rows

is_rows
fn
Returns true if the response is of Rows type (e.g., from a SELECT query).Returns: boolExample:
let insert_result = session
    .query_unpaged("INSERT INTO ks.tab (a) VALUES (1)", &[])
    .await?;
assert!(!insert_result.is_rows());

let select_result = session
    .query_unpaged("SELECT * FROM ks.tab", &[])
    .await?;
assert!(select_result.is_rows());

result_not_rows

result_not_rows
fn
Returns Ok for requests that shouldn’t contain any rows (e.g., INSERT, UPDATE, DELETE).Will return Ok for an INSERT result, but a SELECT result (even an empty one) will cause an error. This is the opposite of into_rows_result().Returns: Result<(), ResultNotRowsError>Example:
// INSERT returns no rows - this succeeds
let insert_result = session
    .query_unpaged("INSERT INTO ks.tab (a) VALUES (1)", &[])
    .await?;
insert_result.result_not_rows()?; // OK

// SELECT returns rows - this fails
let select_result = session
    .query_unpaged("SELECT * FROM ks.tab", &[])
    .await?;
assert!(select_result.result_not_rows().is_err());

into_rows_result

into_rows_result
fn
Transforms the result into QueryRowsResult to enable deserializing rows.Deserializes result metadata and allocates it. Returns an error if the response is not of Rows kind or if metadata deserialization failed.
If the response is not of Rows kind, the original QueryResult is returned in the error variant IntoRowsResultError::ResultNotRows, allowing you to recover it.
Returns: Result<QueryRowsResult, IntoRowsResultError>Example:
// Basic usage
let query_result = session
    .query_unpaged("SELECT a, b FROM ks.tab", &[])
    .await?;

let rows_result = query_result.into_rows_result()?;

let mut rows_iter = rows_result.rows::<(i32, &str)>()?;
while let Some((num, text)) = rows_iter.next().transpose()? {
    println!("{}, {}", num, text);
}
Error Handling:
use scylla::response::query_result::IntoRowsResultError;

let result = session
    .query_unpaged("INSERT INTO ks.tab (a) VALUES (1)", &[])
    .await?;

match result.into_rows_result() {
    Ok(rows_result) => {
        // Process rows
    }
    Err(IntoRowsResultError::ResultNotRows(query_result)) => {
        // Recovered the original QueryResult
        println!("Not a rows result, but no data lost");
    }
    Err(e) => {
        // Other errors (metadata deserialization failed)
        eprintln!("Error: {}", e);
    }
}

Error Types

IntoRowsResultError

Returned by into_rows_result():
  • ResultNotRows(QueryResult) - Result is not of Rows kind. Contains the original QueryResult so it’s not lost.
  • ResultMetadataLazyDeserializationError - Failed to deserialize result metadata.

ResultNotRowsError

Returned by result_not_rows() when the response was unexpectedly of Rows kind.
  • QueryRowsResult - Enables typed access to rows returned from the database
  • Session - Main API for executing queries that return QueryResult
  • Coordinator - Information about the node that coordinated the request

Build docs developers (and LLMs) love