Golang database/sql.Tx.QueryRow function examples
package database/sql
QueryRow executes a query that is expected to return at most one row. QueryRow always return a non-nil value. Errors are deferred until Row's Scan method is called.
Golang database/sql.Tx.QueryRow function usage examples
Example 1:
var num int
err = txn.QueryRow("SELECT COUNT(*) FROM temp").Scan(&num)
if err != nil {
fmt.Println(err)
}
if num != 500 {
fmt.Printf("expected 500 items, not %d", num)
}
Example 2:
var name string
err = tx.QueryRow(`
UPDATE jobs
SET build_number_seq = build_number_seq + 1
WHERE name = $1
RETURNING build_number_seq
`, job).Scan(&name)
if err != nil {
return builds.Build{}, err
}
Reference :
Advertisement
Something interesting
Tutorials
+21.6k Golang : GORM create record or insert new record into database example
+20.5k nginx: [emerg] unknown directive "passenger_enabled"
+8.7k Golang : How to join strings?
+28.6k Get file path of temporary file in Go
+4.9k JQuery : Calling a function inside Jquery(document) block
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+6.2k Golang : Extract XML attribute data with attr field tag example
+5.8k Unix/Linux : How to test user agents blocked successfully ?
+8.8k Golang : Get final balance from bit coin address example
+6k Golang : Convert Chinese UTF8 characters to Pin Yin
+19.6k Golang : Set or Add HTTP Request Headers