expression

rusqlite: bind named SQL parameters

Named placeholders help readers identify values in longer statements. Supply the actual placeholder name, including its prefix. A fixed SQL template remains responsible for the structure of the statement. Run in the accompanying Cargo project. Expected stdout (not executed): total: 12 Common mistake: Confusing a named value placeholder with a column identifier.

Formal Syntax & Structure

rust syntaxrust
named_params! { ":name": value }

Working Example

Example Snippetrust
fn main() -> Result<(), Box<dyn std::error::Error>> {    use rusqlite::{Connection, named_params};    let db = Connection::open_in_memory()?;    let total: i64 = db.query_row("SELECT :price * :qty", named_params! { ":price": 4_i64, ":qty": 3_i64 }, |r| r.get(0))?;    println!("total: {total}");    Ok(())}
Rust Reference