Re: INSERT locking order - Mailing list pgsql-general

From Tom Lane
Subject Re: INSERT locking order
Date
Msg-id 14928.1578605226@sss.pgh.pa.us
Whole thread Raw
In response to INSERT locking order  (Matthew Woodcraft <matthew@woodcraft.me.uk>)
List pgsql-general
Matthew Woodcraft <matthew@woodcraft.me.uk> writes:
> In an INSERT, are the rows guaranteed to be inserted in the order that
> the source query returns its rows, for locking purposes?

I dunno that we "guarantee" that, but it's hard to see why the
code would behave any differently, at present.

> 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?

Well, the issue there is not about the physical insertion order
but the order in which the uniqueness checks happen.  I think
you'd be all right with a traditional-style PG index, but maybe
not with a deferrable unique constraint.

            regards, tom lane



pgsql-general by date:

Previous
From: Peter
Date:
Subject: Re: 12.1 not useable: clientlib fails after a dozen queries (GSSAPI?)
Next
From: Tom Lane
Date:
Subject: Re: 12.1 not useable: clientlib fails after a dozen queries (GSSAPI ?)