sql - Can't insert more than 150 rows -
i using go-sql-driver/mysql insert ton of movies omdb data dump. parsing data , inserting following code:
_, err = database.query("insert `movies` (`name`, `year`, `release_date`, `full_plot`, `genre`, `imdb_id`) values (?, ?, ?, ?, ?, ?)", movie.name, movie.year, movie.releasedate, movie.fullplot, movie.genre, movie.imdbid) if err != nil { return false, nil } return true, nil
it works, 150 rows. doing wrong?
your code seems discard error value returned, shouldn't do; handle gracefully. see error is, if you're opening many connections db, should use database connection pool , set (*db) setmaxopenconns
value.
(*db)query
typically used select
statements return rows, use (*db)exec
or (*stmt)exec
insert
.
i'd advise using db connection pool, , (*sql.db)prepare
prepare statement , run inserts (even concurrently) using prepared statement.
Comments
Post a Comment