diesel

Function insert_or_ignore_into

source
pub fn insert_or_ignore_into<T: Table>(
    target: T,
) -> IncompleteInsertOrIgnoreStatement<T>
Expand description

Creates an INSERT [OR] IGNORE statement.

If a constraint violation fails, the database will ignore the offending row and continue processing any subsequent rows. This function is only available with MySQL and SQLite.

With PostgreSQL, similar functionality is provided by on_conflict_do_nothing.

ยงExample

insert_or_ignore_into(users)
    .values((id.eq(1), name.eq("Jim")))
    .execute(connection)?;

insert_or_ignore_into(users)
    .values(&vec![
        (id.eq(1), name.eq("Sean")),
        (id.eq(2), name.eq("Tess")),
    ])
    .execute(connection)?;

let names = users.select(name).order(id).load::<String>(connection)?;
assert_eq!(vec![String::from("Jim"), String::from("Tess")], names);