Support multi-row insertOrUpdateAll with returning - #848
Open
stefanobaghino wants to merge 4 commits into
Open
stefanobaghino wants to merge 4 commits into
stefanobaghino wants to merge 4 commits into
Conversation
insertOrUpdateAll combined with returning failed at SQL generation with "Building multi-row inserts from this InsertBuilderResult is not supported": the returning path uses Slick's generic composer, which under PostgresProfile defaults to RowsPerStatement.All and calls buildMultiRowInsert on the upsert's InsertBuilderResult, which NativeUpsertBuilder did not override. Override buildMultiRowInsert to repeat the values tuple before the on-conflict clause. Tables with a non-primary-key AutoInc column are not expressible as a single multi-row statement (their padding placeholders live in the once-per-statement on-conflict clause), so they now fail with a clear message pointing at the insertOrUpdateAll(values, RowsPerStatement.One) fallback. Fixes tminglei#847
Author
|
Anything I can do to grab the attention of a maintainer? 🙂 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
insertOrUpdateAllcombined withreturningfailed while the action's SQL was built:The
returningpath uses Slick's generic composer, which underPostgresProfiledefaults toRowsPerStatement.Alland callsbuildMultiRowInserton the upsert'sInsertBuilderResult— whichNativeUpsertBuilderdid not override.This PR overrides
buildMultiRowInsertto repeat the values tuple before theon conflictclause, enabling bothreturning(...).insertOrUpdateAll(values)andinsertOrUpdateAll(values, RowsPerStatement.All). Single-row SQL output is unchanged.Tables with a non-primary-key
AutoInccolumn are not expressible as a single multi-row statement (their padding placeholders live in the once-per-statementon conflictclause), so they now fail with a clear message pointing at theinsertOrUpdateAll(values, RowsPerStatement.One)fallback, which works today and is unchanged.Tested in
PgUpsertSuite: multi-row SQL shape,RowsPerStatement.Allround trip,returninground trip asserting the returned rows, and the clear-error case.Closes #847