Expand description
Compile-time syntax checking for PostgreSQL queries.
postgres-syntax exposes the sql! macro, which parses a PostgreSQL
query string at compile time and returns the string unchanged when parsing
succeeds. If the query is not valid PostgreSQL syntax, compilation fails
with the parser error reported by pg_query.
This crate validates syntax only. It does not connect to a database, inspect your schema, validate table or column names, or type-check query parameters.
§Example
use postgres_syntax::sql;
let query = sql!("SELECT name, email_address FROM users WHERE id = $1");
assert_eq!(
query,
"SELECT name, email_address FROM users WHERE id = $1",
);Invalid SQL produces a compile error:
ⓘ
use postgres_syntax::sql;
let _ = sql!("SELECT * FROM users WHERE id = $1 BLARG");Macros§
- sql
- Checks a PostgreSQL query for syntax errors at compile time.