Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Make TryInsert functions within the packages module use INSERT ... ON CONFLICT #21063
base: main
Are you sure you want to change the base?
Make TryInsert functions within the packages module use INSERT ... ON CONFLICT #21063
Changes from 25 commits
7f4e851
b29ab42
470064c
9c83ab8
bf94b55
8d3864a
71522ea
7843fe9
abcf334
430f964
5dff21a
f934a98
b3db6da
5bc4924
8f7987c
fc5d9aa
7ec881f
d8aa794
3f39045
15855df
38d540b
a941cba
5ef7902
04efbf9
2283b23
a282e66
62b1e20
f1222e8
25abc72
028b5a6
1c17006
ac6862a
dc4638c
ecd3eea
bf18cf8
1a6f5df
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to bother, but why
INSERT IGNORE
doesn't work forautoIncrCol != nil
?If you meant to do it for
LastInsertId
, I think it (ON DUPLICATE KEY UPDATE) doesn't work, either.Otherwise I really can not understand its purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you try it. When I wrote this code it required the ON DUPLICATE KEY UPDATE and not the IGNORE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I have tried (update: out-dated)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(merged into next comment below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it really works from XORM or Golang MySQL Driver, there should be some complete test cases for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you really need is this (update: out-dated)
update id=last_insert_id(id)
Table:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a)
I would have thought that last_insert_id() requires that there are no other id insertions in the meantimeid = last_insert_id() would cause updates on conflicts which is completely the wrong thing to do .b) id = id avoids that.
c) IGNORE is only used when there is no autoincrement ID present in the table where there is no id to update.
d) I've written some tests now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a) last_insert_id is the last successfully inserted ID in current session, it's always safe across transactions. And it won't be reset if a new insertion fails. you might have seen some incorrect last_insert_id/unrelated during your test.
c) you can also do
on duplicate update set col[0] = col[0]
, then no separateignore
need to be added IMO.b) & d) the tests are incorrect at the moment. see the comment below. #21063 (comment)
Update: out-dated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MySQL demo (update: out-dated, the demo is for filling the ID)