-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Batch insert #5086
Comments
@kevinburke I know I've mentioned this before, but this issue is also resolved in the es6/knex re-write:
Knex supports batch insert ootb, and I bypass |
This is probably because, without an explicit It does constitute an unfortunate semantic difference between the reference implementation and the adapter-specific implementation. In this case I think it's correct to fail the entire insert if any one of the records fails; this would require a fix in Waterline core. |
Part of the issue with the non-optimized https://github.com/balderdashy/waterline/issues/1007#issuecomment-145177976 |
Thanks for posting, @kevinburke. I'm a repo bot-- nice to meet you! It has been 30 days since there have been any updates or new comments on this page. If this issue has been resolved, feel free to disregard the rest of this message. On the other hand, if you are still waiting on a patch, please:
Thanks so much for your help! |
Hey @kevinburke @kevinburkeshyp, If you don't want to do this or don't have time, let me know here and I'll reopen those issues until they are placed in a roadmap file. |
@kevinburkeshyp @devinivy I went ahead and did this so we don't lose them https://github.com/balderdashy/sails-postgresql/blob/master/ROADMAP.md |
For posterity: you can check out more info on where this stands in the conversation here: https://gitter.im/balderdashy/sails?at=5812a124806316005dc9e6fb |
Currently
Model.create([record1, record2, ..., recordN])
opens N connections and issues N inserts of one record each.Postgres supports inserting multiple records at once, for example:
I believe this would be a good change, since it opens 1 connection instead of N connections, and it maps more intuitively to what you think would happen if you called
Model.create([])
.However, in the current state, if a record fails validation in the database (a uniqueness constraint, foreign key reference, not null constraint, or check constraint, for example), the current master will insert every other record. Multi-row
INSERT INTO ... VALUES ()
will not insert any rows if one row fails constraint checks. This is a breaking change and would probably require a major version bump. (That said I'm not sure whether sails-postgresql guarantees all N-1 rows get written if one row fails? doesasync.each
early exit if one function throws?)Another option might be to issue the queries sequentially on one connection:
I'm not sure how the client would handle multiple RETURNING * lines, maybe it would and maybe it wouldn't. This would not write any rows after a failing row, but it would write any rows beforehand.
I believe
createEach
would have to be modified to avoid theasync.each
call, and I don't believewaterline-sequel
supports batch insert so we'd need to build our own query there.The text was updated successfully, but these errors were encountered: