volatiletech / sqlboiler

Generate a Go ORM tailored to your database schema.
BSD 3-Clause "New" or "Revised" License
6.73k stars 544 forks source link

mysql Error 1390: Prepared statement contains too many placeholders #572

Closed bugzpodder closed 5 years ago

bugzpodder commented 5 years ago

Mysql has a limit of 65536 placeholders in each query.
If you query for enough items you'll hit:

Added error: (models: failed to assign all query results to User slice: bind failed to execute query: Error 1390: Prepared statement contains too many placeholders), path=()

models: failed to assign all query results to User slice: failed to eager load Location: failed to eager load UserLocation: Error 1390: Prepared statement contains too many placeholders

Perhaps sqlboiler can handle this internally so I don't have to?

Get a table with > 65535 rows, do a models.Users(UserWhere.ID.GT(1), Load("Location")).AllG()

aarondl commented 5 years ago

I don't think we can safely do so. You'll have to resort to raw queries to do this more efficiently or some sort of paging mechanism. Remember that all of sqlboiler's generated methods are mostly for convenience and although they are well optimized they are general methods meaning that they'll usually fall over in edge cases like this :)