Skip to content

How build an insert query with N rows? (Bulk/batch insert) #401

Answered by billy1624
enheit asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @enheit, welcome!

A single insert statement with multiple rows of value is more performant. To construct such insert statement, you need to call either values / values_panic methods multiple times. See below for example :)

sea-query/tests/mysql/query.rs

Lines 1057 to 1078 in eb5705e

#[test]
#[allow(clippy::approx_constant)]
fn insert_3() {
assert_eq!(
Query::insert()
.into_table(Glyph::Table)
.columns([
Glyph::Image,
Glyph::Aspect,
])
.values_panic(vec![
"04108048005887010020060000204E0180400400".into(),
3.1415.into(),
])
.values_panic(vec![
Value::String(None),
2.1345.into(),
])
.to_…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@enheit
Comment options

@billy1624
Comment options

Answer selected by enheit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants