Sitelet https://github.com/tminglei/slick-pg/pull/848
Skip to content

Support multi-row insertOrUpdateAll with returning - #848

Open
stefanobaghino wants to merge 4 commits into
tminglei:masterfrom
stefanobaghino:multi-row-upsert-returning
Open

stefanobaghino wants to merge 4 commits into
tminglei:masterfrom
stefanobaghino:multi-row-upsert-returning

Conversation

@stefanobaghino

Copy link
Copy Markdown

insertOrUpdateAll combined with returning failed while the action's SQL was built:

slick.SlickException: 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.

This PR overrides buildMultiRowInsert to repeat the values tuple before the on conflict clause, enabling both returning(...).insertOrUpdateAll(values) and insertOrUpdateAll(values, RowsPerStatement.All). Single-row SQL output is unchanged.

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, which works today and is unchanged.

Tested in PgUpsertSuite: multi-row SQL shape, RowsPerStatement.All round trip, returning round trip asserting the returned rows, and the clear-error case.

Closes #847

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
@stefanobaghino

Copy link
Copy Markdown
Author

Anything I can do to grab the attention of a maintainer? 🙂

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.

insertOrUpdateAll with returning fails: "Building multi-row inserts from this InsertBuilderResult is not supported"

1 participant