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

Upsert with compound primary key #38

Open
Isaac-Flath opened this issue Nov 11, 2024 · 2 comments
Open

Upsert with compound primary key #38

Isaac-Flath opened this issue Nov 11, 2024 · 2 comments

Comments

@Isaac-Flath
Copy link
Contributor

upsert does not work as I would expect with a compound primary key. The workaround I use is to use insert with replace=True to accomplish what I think upsert should do.

This is a minimal repro of the issue I ran into when developing on the solveit app: https://gist.github.com/Isaac-Flath/cc9b3c5d28219725235b00241ce4082a

FYI @pydanny @audreyfeldroy @jph00

@pydanny
Copy link
Contributor

pydanny commented Nov 11, 2024

In fastlite/sqlite-minutils upsert is coded entirely in Python, but you've found a way to get that logic through SQLite dialogue through the use of INSERT OR REPLACE.

Interestingly, Sqlite supports two upsert methods:

  1. INSERT OR REPLACE - What @Isaac-Flath discovered
  2. ON CONFLICT DO - What AI and search suggests we should do

If my reading of the specs is correct, I think OR REPLACE is closer to what we want implemented. So for me it will be interesting to see how your workaround addresses data quality.

@pydanny
Copy link
Contributor

pydanny commented Nov 11, 2024

Apparently the problem with INSERT OR REPLACE is it ignores integrity errors, just sticks in null values because the engine allows that. Exploring what that means.

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

No branches or pull requests

2 participants