Re: psycopg concurrency control

From: John Lb <johnlb77(at)gmail(dot)com>
To: Christophe Pettus <xof(at)thebuild(dot)com>, psycopg(at)postgresql(dot)org
Subject: Re: psycopg concurrency control
Date: 2016-09-13 00:00:29
Message-ID: CANqFGQzVExNk8AoXw+hqAGrZQrkixR45K6w5c8gHSRFLW7Ut=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

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(at)thebuild(dot)com> wrote:

>
> On Sep 12, 2016, at 4:39 PM, John Lb <johnlb77(at)gmail(dot)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.
>
> --
> -- Christophe Pettus
> xof(at)thebuild(dot)com
>
>

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Christophe Pettus 2016-09-13 00:01:42 Re: psycopg concurrency control
Previous Message Christophe Pettus 2016-09-12 22:48:26 Re: psycopg concurrency control