-
Notifications
You must be signed in to change notification settings - Fork 73
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
Feature Request: Provide InsertIgnore and InsertIgnoreMany #149
Comments
Can you tell me more about your use case? Will something like this work for you? package reform
// CheckDuplicate returns nil if err is nil or duplicate key error.
// It returns err unmodified otherwise.
func CheckDuplicate(err error) error {
…
} if err := q.Insert(str); reform.CheckDuplicate(err) != nil {
…
} |
Nice! Thank you, that will work nicely for INSERT ( How about for multi-value inserts? ( |
What about something similar to what we currently have for tail := "on conflict do nothing"
querier.Insert(record, tail) Though that would work for postgres, but not with @evanmcclure's issue with the I found two ways to deal with this with the current implementation with postgres: check the error class, or construct the query and directly call For reference, that's how you can do something similar to the err = querier.Insert(record)
pgErr, ok := err.(*pq.Error)
if !ok || pgErr.Code.Class() != "23" { // 23 stands for "Class 23 — Integrity Constraint Violation" in postgres, see https://www.postgresql.org/docs/9.3/errcodes-appendix.html
return err
} |
Hmm, my solution isn't really one, because the conflict isn't handled on the SQL side any existing transaction is invalidated. Edit: that's also valid for @AlekSi's suggestion using the |
Hi. We love the library. It's super simple and very powerful.
We'd love to see functionality for ignoring duplicate keys when inserting. Can you provide alternatives for
Insert
andInsertMany
that provideINSERT IGNORE
functionality?You can find more information here:
INSERT IGNORE
- https://mariadb.com/kb/en/library/insert-ignore/ON CONFLICT DO NOTHING
- https://www.postgresql.org/docs/9.5/static/sql-insert.html#SQL-ON-CONFLICTThank you,
Evan
Sunnyvale, CA
The text was updated successfully, but these errors were encountered: