Re: psycopg concurrency control
От
John Lb
Тема
Re: psycopg concurrency control
Дата
Msg-id
CANqFGQzVExNk8AoXw+hqAGrZQrkixR45K6w5c8gHSRFLW7Ut=g@mail.gmail.com
Список
Дерево обсуждения
psycopg concurrency control John Lb <johnlb77@gmail.com>
Re: psycopg concurrency control Christophe Pettus <xof@thebuild.com>
Re: psycopg concurrency control John Lb <johnlb77@gmail.com>
Re: psycopg concurrency control Christophe Pettus <xof@thebuild.com>
Again thanks . Now it is more clear for me after checking information about unique index. Again I am not a DB guy , but more on embedded systems where I also have to deal with concurrency and race conditions on another level .
OK let's take the hypothetical situation again .
Let's say I created the unique index on Name after the table is created.
Thread A and B have the same snapshot of the table at the beginning where there is no bob in any row . Thread A writes bob in a row successfully , and then when Thread B tries to write the name bob , an error notification will appear indicating name bob is already in the row . Is this right ??
Thanks
On Mon, Sep 12, 2016 at 7:40 PM, Christophe Pettus <xof@thebuild.com> wrote:
On Sep 12, 2016, at 4:39 PM, John Lb <johnlb77@gmail.com> wrote:
> In the table is a column called Name . Thread A wants to insert the name bob in a row , and at the same time Thread B wants to insert the name bob as well. But before inserting the names , thread A and thread B do a SELECT to check if there is the name bob already inserted in the table , if not then Thread A inserts name bob , and on the following row , I believe , Thread B also inserts name bob in the table . So there are two names of bob in the table and I want to prevent this .
This can be prevented with a unique index on Name.
В списке psycopg по дате отправления