insert_jsonb_batch

Function insert_jsonb_batch 

Source
pub async fn insert_jsonb_batch(
    client: &Client,
    table_name: &str,
    rows: Vec<(String, Value)>,
    source_type: &str,
) -> Result<()>
Expand description

Insert multiple JSONB rows in a batch

Inserts multiple rows efficiently using a multi-value INSERT statement. This is significantly faster than individual inserts for large datasets.

§Arguments

  • client - PostgreSQL client connection
  • table_name - Name of the table (must be validated)
  • rows - Vector of (id, data) tuples
  • source_type - Source database type (‘sqlite’, ‘mongodb’, or ‘mysql’)

§Security

Uses parameterized queries for all data. table_name must be validated.

§Performance

Batches rows into groups of 1000 to avoid PostgreSQL parameter limits.

§Examples

let table_name = "users";
validate_table_name(table_name)?;
let rows = vec![
    ("1".to_string(), json!({"name": "Alice", "age": 30})),
    ("2".to_string(), json!({"name": "Bob", "age": 25})),
];
insert_jsonb_batch(client, table_name, rows, "sqlite").await?;