0Pricing
Go Academy · Lesson

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

  1. Opening a Connection
  2. Querying Rows
  3. Prepared Statements
  4. Transactions
← Back to Go Academy