Skip to content

ErrorResponse ignored during Sync message in .execute() #832

@maddyblue

Description

@maddyblue
fn main() -> Result<(), postgres::Error> {
    use postgres::{Client, NoTls};
    let mut client = Client::connect("host=localhost user=postgres", NoTls)?;

    let _ = client.batch_execute("drop table t");
    client.batch_execute("create table t (i int, unique (i) DEFERRABLE INITIALLY DEFERRED);")?;
    client.execute("insert into t values (1);", &[])?;
    client.execute("insert into t values (1);", &[])?;
    client.execute("insert into t values (1);", &[])?;

    println!("rows: {}", client.query("SELECT * FROM t", &[])?.len());

    Ok(())
}

Here we expect 3 rows to be present because the three execute calls succeed, however only one row is actually present. This happens because the ErrorResponse message is produced only after postgres attempts to commit the transaction in response to the Sync message. Using deferred constraints causes postgres to delay constraint checking until transaction commit time.

See https://github.com/MaterializeInc/database-issues/issues/2673

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