Skip to main content

execute

Function execute 

Source
pub fn execute(
    query: &str,
    query_args: Option<&[Arg<'_>]>,
) -> Result<QueryResult>
Expand description

Execute a one-off query using an in-memory connection.

This function creates a temporary in-memory database connection, executes the query, and returns the result. It’s suitable for queries that don’t require persistent storage.

§Arguments

  • query - The SQL query string to execute
  • query_args - Optional array of query arguments (e.g., output format)

§Returns

Returns a QueryResult containing the query output, or an Error if the query fails.

§Examples

use chdb_rust::execute;
use chdb_rust::arg::Arg;
use chdb_rust::format::OutputFormat;

// Simple query with default format
let result = execute("SELECT 1 + 1 AS sum", None)?;
println!("{}", result.data_utf8_lossy());

// Query with JSON output format
let result = execute(
    "SELECT 'Hello' AS greeting, 42 AS answer",
    Some(&[Arg::OutputFormat(OutputFormat::JSONEachRow)])
)?;
println!("{}", result.data_utf8_lossy());

§Errors

This function will return an error if:

  • The query syntax is invalid
  • The connection cannot be established
  • The query execution fails