INSERT locking order

From: Matthew Woodcraft <matthew(at)woodcraft(dot)me(dot)uk>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: INSERT locking order
Date: 2020-01-09 20:50:29
Message-ID: 1578602959.23rey5xcjc.astroid@golux.woodcraft.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In an INSERT, are the rows guaranteed to be inserted in the order that
the source query returns its rows, for locking purposes?

For example, if have

CREATE TABLE foo (
foo_id INTEGER,
PRIMARY KEY (foo_id)
);

and I run two concurrent copies of

INSERT INTO foo (SELECT n FROM ... ORDER BY n);

is there any guarantee that I'll get a unique constraint violation
rather than a deadlock?

-M-

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter 2020-01-09 20:53:17 Re: 12.1 not useable: clientlib fails after a dozen queries (GSSAPI ?)
Previous Message github kran 2020-01-09 20:47:26 Re: Upgrade PostgreSQL 9.6 to 10.6