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
+35.3k Golang : Strip slashes from string example
+8.6k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+6.3k Golang : How to get capacity of a slice or array?
+6.8k Golang : Join lines with certain suffix symbol example
+19.2k Golang : Populate dropdown with html/template example
+21.5k Golang : How to read float value from standard input ?
+6.1k Golang : How to write backslash in string?
+5.2k Golang : PGX CopyFrom to insert rows into Postgres database
+20.2k Golang : Compare floating-point numbers
+5.2k Golang : Issue HTTP commands to server and port example