-
-
Notifications
You must be signed in to change notification settings - Fork 478
Inserting multiple values at the same time #336
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
Comments
The simple option is to build up a query string dynamically based on how many things you want to insert that looks like: The more complex option is to use a COPY query. This takes some more work to set up but is great if you need to insert a ton of data: https://docs.rs/postgres/0.15.2/postgres/stmt/struct.Statement.html#method.copy_in. You can use the postgres-binary-copy crate to handle the data encoding for you: https://docs.rs/postgres-binary-copy/0.5.0/postgres_binary_copy/ |
Thanks! |
I'm running into this issue as well - my main painpoint is, as I discovered today, Redshift doesn't support the COPY query, so mass inserts are kind of painful if I have to potentially insert 100s of rows at a time with 10+ fields. |
Hm, so using the dynamic statement approach I cannot create a |
While not the same as this issue, the answer to @drewhk (and my future self)'s question: #133 (comment) |
Sorry to open this again I am using this code to insert multiple values, is there a better option :
|
FWIW, |
This is a single insert. What should I do if I want to insert multiple values into the database at the same time? Until now I just used a simple for loop with a prepared statement but this is relatively slow.
At least from the postgres sql docs this seems possible
How should I do it? Should I create a really long sql query or is there a better way to insert multiple values at the same time?
The text was updated successfully, but these errors were encountered: