Skip to content
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

On conflict do nothing for MySQL #682

Closed
wants to merge 1 commit into from

Conversation

tyt2y3
Copy link
Member

@tyt2y3 tyt2y3 commented Aug 22, 2023

Continuing #680 in trying to solve SeaQL/sea-orm#1790

However I want to gather comments here whether INSERT IGNORE is a good substitution for ON CONFLICT DO NOTHING

It seems a better way would be to do ON DUPLICATE KEY UPDATE id=id, however this requires us to add an API to the frontend to allow users to pass in the primary key.

https://stackoverflow.com/questions/4596390/insert-on-duplicate-key-do-nothing

* fixed on conflict do nothing for MySQL

* merged prepare_ignore into prepare_insert

* added test cases
@tyt2y3
Copy link
Member Author

tyt2y3 commented Aug 22, 2023

I think INSERT IGNORE is an inappropriate solution to ON CONFLICT DO NOTHING.

I think we should add a special method for MySQL that would result in ON DUPLICATE KEY UPDATE id=id.

https://github.com/SeaQL/sea-query/blob/a784868fd7bdcd690529fcbb0874b2c4dbb18d16/src/query/on_conflict.rs#L152C7-L152C7

In SeaORM we have the PK information.

May be OnConflictAction::DoNothing can be extended to DoNothing(Option<DynIden>) to hold the PK? Or is there a better way to transparently handle this?

@tyt2y3 tyt2y3 closed this Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants