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

Generate update set on conflict for upserts #145

Merged
merged 1 commit into from
Oct 31, 2024

Conversation

kaaveland
Copy link
Contributor

When upserting to tables with only key columns, typo would generate do nothing as a conflict resolution. This has the disadvantage of making the query not execute the returning part, which meant that in cases where an upsert was executed targeting a single row, no rows would return and the generated code would cause an error.

As a workaround, we generate update set k = excluded.k for an arbitrary key column k instead. This causes the returning part of the query to run but shouldn't change the value of the row as typo sees it.

  • Add failing test case for upserting on an existing row
  • Make the test case work by generating update set instead of do nothing

When upserting to tables with only key columns, typo would generate `do nothing`
as a conflict resolution. This has the disadvantage of making the query not
execute the `returning` part, which meant that in cases where an upsert was
executed targeting a single row, no rows would return and the generated code
would cause an error.

As a workaround, we generate `update set k = excluded.k` for an arbitrary key
column k instead. This causes the `returning` part of the query to run but
shouldn't change the value of the row as typo sees it.

- Add failing test case for upserting on an existing row
- Make the test case work by generating `update set` instead of `do nothing`
@oyvindberg oyvindberg merged commit 4f36771 into oyvindberg:main Oct 31, 2024
8 checks passed
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