Skip to main content

execute_with_params

Function execute_with_params 

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

Execute a one-off query with ClickHouse {name:Type} parameter binding.

Counterpart to execute. Parameter values are bound in the chDB library and never interpolated into the SQL text. Names in params need not match placeholder order. An empty params list is a plain query: placeholders then fail with a substitution error.

§Examples

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

let result = execute_with_params(
    "SELECT {x:UInt64} AS v",
    Some(&[Arg::OutputFormat(OutputFormat::CSV)]),
    [("x", 7_u64)],
)?;

§Errors

This function will return an error if:

  • The query syntax is invalid
  • A {name:Type} placeholder has no matching param
  • A value cannot be parsed as the type declared in the placeholder
  • The connection cannot be established
  • The query execution fails
  • A connection is already open on a data path, since the in-memory connection this opens would be a second one. See Error::PathConflict.