Skip to content

Ability to insert multiple rows by specifying multiple rows in VALUES? #218

Closed
@carols10cents

Description

@carols10cents

What I'd like to be able to do is something like this:

let categories = vec!["shoes", "socks"];

try!(tx.execute("
    INSERT INTO categories (category)
    VALUES $1",
    &[&&categories[..]]
));

And I expected the SQL generated to be:

INSERT INTO categories (category)
VALUES ('shoes'), ('socks');

The code above compiles, but I get a panic on unwrapping:

Db(DbError { 
    severity: "ERROR", 
    code: SyntaxError, 
    message: "syntax error at or near \"$1\"", 
    detail: None, hint: None, position: Some(Normal(59)), where_: None, schema: None, 
    table: None, column: None, datatype: None, constraint: None, file: Some("scan.l"), 
    line: Some(1087), routine: Some("scanner_yyerror")
})

Which looks to me like the $1 wasn't substituted at all.

Is there a way to do this currently that I'm missing? If not, is this something that you'd want rust-postgres to support, or would it be better as a separate crate, something like activerecord-import?

Thanks!! ❤️

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