Querying Rows
Read result sets.
Querying Result Sets
Use Query for statements that return rows, like SELECT. It returns a *sql.Rows you iterate over. For a single value, QueryRow is simpler.
db.Query
Query sends the SQL and returns rows plus an error. Always check the error before using the rows.
rows, err := db.Query("SELECT id, name FROM users WHERE active = $1", true)
if err != nil {
log.Fatal(err)
}All lessons in this course
- Opening a Connection
- Querying Rows
- Prepared Statements
- Transactions