I am using Postgres 9.5 with and using golang library lib/pq to interact with database. I execute a select query which returns multiple rows and then I iterate using for rows.Next()
Is there anyway I ca stop before the lat record. I want to print something else on console if its the last record. Something like the following:
for rows.Next() {
var id string
err = rows.Scan(&id)
if err != nil {
log.Printf("Error in rows.Scan: %s
", err)
}
if (row is not last) {
fmt.Println(id + "I am not last")
} else {
fmt.Println(id + "I am last")
}
}