Last Updated: May 22, 2026
A prepared statement asks the database to parse and plan a SQL query once, then execute it many times with different argument values. In Go, db.Prepare returns a *sql.Stmt whose Query, QueryRow, and Exec methods mirror the ones on *sql.DB but skip the parse step on every call. The win shows up in tight loops that run the same query with different arguments. The trap is forgetting to call stmt.Close(), which leaks server-side resources.