I am using goLang lib/pq driver and trying to fetch rows from database.
rows, err := db.Query("select id, name from mytable limit 5")
I want to have a if else clause which checks if there are rows in result set and I did this:
if(!rows.Next()){
log.Printf("no rows returned")
} else {
log.Printf("rows returned")
}
but this always return me 1 record less and I assume its because of the if
clause it skips one record because as soon as I remove if
clause I get all records correctly. How can I know the count of rows returned from the select query without executing another query?