postgresql - How to identify the last row in the result set postgres? -
i using postgres 9.5 , using golang library lib/pq interact database. execute select query returns multiple rows , iterate using for rows.next()
there anyway ca stop before lat record. want print else on console if last record. following:
for rows.next() { var id string err = rows.scan(&id) if err != nil { log.printf("error in rows.scan: %s\n", err) } if (row not last) { fmt.println(id + "i not last") } else { fmt.println(id + "i last") } }
you can impliment while loop in go.
notlast := rows.next() notlast { //... rows.scan notlast = rows.next() if notlast { fmt.println(id + "i not last") } else { fmt.println(id + "i last") } }
Comments
Post a Comment