-
Notifications
You must be signed in to change notification settings - Fork 614
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
Return inserted ids MySQL #279
Conversation
[number_of_inserts, []] | ||
if first_inserted_id | ||
last_inserted_id = first_inserted_id + number_of_inserts - 1 | ||
ids = (first_inserted_id..last_inserted_id).to_a |
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.
@zdennis what do you think about this approach?
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.
@robertomiranda, thank you for contributing to ar-import! With regard to your question above I have the same concerns as @tonic20 and @jkowens. I'd want to ensure that we however this implemented we can guarantee reliability and avoid unsuspecting issues when the returned IDs are wrong.
The database table would need to be InnoDB with |
else | ||
value_sets = ::ActiveRecord::Import::ValueSetsBytesParser.parse(values, | ||
reserved_bytes: sql_size, | ||
max_bytes: max) | ||
value_sets.each do |value_set| | ||
number_of_inserts += 1 | ||
sql2insert = base_sql + value_set.join( ',' ) + post_sql | ||
insert( sql2insert, *args ) | ||
ids << insert( sql2insert, *args ) |
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.
This will result in missing ids because this is a batch operation.
Would be nice to have this feature. It will work fine for all users with |
This will also not work when there are duplicates and you use on_duplicate_key_update, right? Than it returns wrong id's probably. |
@philipgiuliani you're correct, this would not work with on_duplicate_key_update. |
I'm going to close this PR for now because it doesn't seem like MySQL provides a good solution for this problem at the moment. With the need to support |
ref #94