expression

SQLx: bind PostgreSQL query parameters

A bound parameter represents a data value, not executable SQL syntax. PostgreSQL placeholders are numbered starting at $1. SQLx keeps the query text separate from the bound value. The offline example inspects text only; it cannot establish that the database will accept it. No database connection is required by this example. Expected stdout (not executed): SQL: SELECT $1::text Common mistake: Building the SQL string by interpolating user-controlled values. Binding does not replace identifier allowlists for table or column names.

Formal Syntax & Structure

rust syntaxrust
sqlx::query::<Postgres>("SELECT $1::text").bind(value)

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() -> Result<(), Box<dyn std::error::Error>> {    use sqlx::{Execute, Postgres};    let query = sqlx::query::<Postgres>("SELECT $1::text").bind("O'Neil");    println!("SQL: {}", query.sql());    Ok(())}
Rust Reference