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

Add insertBatch? #140

Open
kolemannix opened this issue Sep 13, 2024 · 1 comment
Open

Add insertBatch? #140

kolemannix opened this issue Sep 13, 2024 · 1 comment

Comments

@kolemannix
Copy link

I believe there is currently no way to perform a batch insert that returns generated values, due to the fact that insertStreaming uses the COPY API. This is great except for cases where the generated values are required by the application. Running a series of plain inserts wrapped in a ConnectionIO.sequence performs far worse than a single insert ... values ... statement.

upsertBatch is close in terms of API shape but doesn't quite work for this case because doesn't accept an Unsaved row.

@oyvindberg
Copy link
Owner

Yeah, it's not possible with UnsavedRows, unfortunately. The reason is that the SQL is dynamically generated based on which Defaulted columns you choose to override, and this will vary row by row. It was a wonder that I got it working with the COPY interface at all, so that's as far as we can go in that direction, unless someone knows something I don't.

The only direct workarounds you have here would be:

  • don't use columns with defaulted values when you want to batch insert
  • copy/paste the generated code for non-Unsaved Row and adapt it to the default values you do want to plug in (if any)

On the typo side there are things we could do, but it would require codegen changes. One obvious thing would be to disable the functionality where you can override values for defaulted columns. This likely wouldn't be very invasive code-wise, and would lead us to a situation where the query is no longer dynamic per row, and we can get returned rows again.

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