-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it safe to use LastInsertId() ? #377
Comments
No, it is not - the connection pooling by database/sql makes it unsafe. You can use it in transactions, though. |
I think he means Result.LastInsertId() which is implemented in result.go#L16 which just uses the So it's perfectly safe to use concurrently because it's stored in the result and has nothing to do with the connections. |
What is NOT safe is executing this after your insert: SELECT LAST_INSERT_ID() Because that might use a different connection because of the pooling. |
Yeah, thanks. Exactly what @erikdubbelboer says. |
Thanks for the input i did mean Result.LastInsertId() |
If connection is shared between many threads . Is it safe to use LastInsertId() ? Thanks for help
The text was updated successfully, but these errors were encountered: