As PostgreSQL connector I import following package:
_ "github.com/lib/pq"
The query I run is:
res, err := db.Query("SELECT id FROM applications WHERE email='" + email + "'")
where email is naturally a string. One way to count the number of rows in res is by following snippet
count:=0
for res.Next() {
count++
//some other code
}
but there should be some simpler (and quicker) way. It seems RowsAffected() is not the way to go. So, what is your suggestion?
Use the COUNT
function:
"SELECT count(*) FROM applications WHERE email='" + email + "'"