Skip to content

Inserting multiple values at the same time #336

Closed
@MaikKlein

Description

@MaikKlein
    conn.execute("INSERT INTO person (name, data) VALUES ($1, $2)",
                 &[&me.name, &me.data]).unwrap();

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

INSERT INTO products (product_no, name, price) VALUES
    (1, 'Cheese', 9.99),
    (2, 'Bread', 1.99),
    (3, 'Milk', 2.99);

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions