Re: Duplicate key error

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Andrus <kobruleht2(at)hot(dot)ee>, pgsql-general(at)postgresql(dot)org
Subject: Re: Duplicate key error
Date: 2021-03-03 20:19:37
Message-ID: d669cc09-aa93-cdf3-5030-37318d2a9001@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 3/3/21 11:59 AM, Andrus wrote:
> Hi!
>>
>> And if that name already exists there would be a duplicate key error.
>
> Name cannot exist:  First delete deletes its value. Tables are not
> changed by external process during transaction. As double insurance,
> insert perfoms additional existence check and adds only if key does not
> exist.

The error message:

"
duplicate key value violates unique constraint "session_pkey"
Key (workplace)=(WIN-N9BSKUNKBC8 ) already exists.
"

says something else is inserting/updating using that key value. So
obviously your script is not catching all the conflicts. At this point
your best bet is to monitor the Postgres log and see what else is
happening at the time of the error. I'm guessing you will find another
process working on that table.

>
> >Last inserted row data should remain.
>>
>> I'm not understanding the above.
>
> This table should contain last login time, user and ip address. It
> should be updated by every process on login. For this old entry is
> removed if it exists and new entry with same primary key is added.
>
> Andrus.
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Valeria Kaplan 2021-03-03 22:09:45 Re: Code of Conduct: Russian Translation for Review
Previous Message Andrus 2021-03-03 20:02:08 Re: Duplicate key error