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

Support SQLITE's ON CONFLICT clause #510

Closed
johnpyp opened this issue May 22, 2023 · 2 comments
Closed

Support SQLITE's ON CONFLICT clause #510

johnpyp opened this issue May 22, 2023 · 2 comments
Labels
api Related to library's API enhancement New feature or request sqlite Related to sqlite wontfix This will not be worked on

Comments

@johnpyp
Copy link

johnpyp commented May 22, 2023

Sqlite supports a non-standard ON CONFLICT clause (https://www.sqlite.org/lang_conflict.html) that determines how inserts/updates/create tables work, taking into account the entire row. Notably, this is distinct from sqlite's implementation of ON CONFLICT for use in its upsert clause - https://www.sqlite.org/lang_UPSERT.html.

An example usecase of this feature is a simplified upsert, that just replaces the underlying with the new row if there's a primary key or unique constraint violation of any sort, instead of having to declare every conflict resolution separate from the main insert body:

(Note the use of OR REPLACE instead of ON CONFLICT REPLACE, which is part of the syntax to be less verbose in INSERT/UPDATE statements)

INSERT OR REPLACE INTO subscriptions (
  id, -- The primary key, if this is conflicted, the row gets deleted and replaced with this new one
  many,
  keys,
  that,
  will,
  always,
  be,
  upserted
) VALUES ( ... )
@koskimas
Copy link
Member

koskimas commented May 22, 2023

You can get the same result like this https://kyse.link/?p=s&i=wSDqoqqCK5mM9d5z5Ywy. Since this is trivially implemented using the current features, I don't think we should add another non-standard method.

@igalklebanov igalklebanov added enhancement New feature or request wontfix This will not be worked on sqlite Related to sqlite api Related to library's API labels May 22, 2023
@enrique-lozano
Copy link

enrique-lozano commented May 22, 2024

You can get the same result like this https://kyse.link/?p=s&i=wSDqoqqCK5mM9d5z5Ywy. Since this is trivially implemented using the current features, I don't think we should add another non-standard method.

But here in your example we can not insert arrays right? If we convert the user object to an array we can insert this array but the doUpdateSet fails. Maybe we should wait for #976 to get this functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to library's API enhancement New feature or request sqlite Related to sqlite wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants