expression
SQLx MySQL: bind dynamic values
SQLx generates question-mark placeholders for MySQL rather than PostgreSQL numbered placeholders. The value is stored separately as a bind argument. QueryBuilder does not validate SQL against a server or make arbitrary pushed SQL safe. The example only constructs SQL. Offline example; no server is contacted. Expected stdout (not executed): SELECT id FROM items WHERE label = ? Common mistake: Concatenating a user-provided string as SQL or assuming all backends share placeholder syntax.
Formal Syntax & Structure
rust syntaxrust
QueryBuilder::<MySql>::new(sql).push_bind(value)Working Example
Example Snippetrust
fn main() -> Result<(), Box<dyn std::error::Error>> { use sqlx::{MySql, QueryBuilder}; let mut q = QueryBuilder::<MySql>::new("SELECT id FROM items WHERE label = "); q.push_bind("O'Neil"); println!("{}", q.sql()); Ok(())}