Answer the question
In order to leave comments, you need to log in
How to get the result of a sql query in go in parts?
I'm trying to query a database that returns a lot of data. How can you process them as they are received, let's say 1000 rows each? Allows such standard database/sql?
Answer the question
In order to leave comments, you need to log in
Allows by default, but not by a thousand rows, but in the form of a cursor that moves with each call to rows.Next(), which you can read more about in the database/sql documentation:
https://golang.org/pkg/database/sql /#Rows
There is also an example that illustrates this:
rows, err := db.Query("SELECT ...")
...
defer rows.Close()
for rows.Next() {
var id int
var name string
err = rows.Scan(&id, &name)
...
}
err = rows.Err() // get any error encountered during iteration
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question