From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sylvain Déve <sylvain.deve@protonmail.com>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Update concurrency
Date: Mon, 20 Dec 2021 10:07:37 -0500
Message-ID: <2377043.1640012857@sss.pgh.pa.us> (raw)
In-Reply-To: <-zxRtNEMT5cJjoFNR4LphpHl907G9wjMd-xShnDUyjZg5cgXZQpRdsNHe6OY96_8eyP9s0cyttLKUwv4FyRrirbUGeEoQe22M0lpaFJSGuo=@protonmail.com>
References: <-zxRtNEMT5cJjoFNR4LphpHl907G9wjMd-xShnDUyjZg5cgXZQpRdsNHe6OY96_8eyP9s0cyttLKUwv4FyRrirbUGeEoQe22M0lpaFJSGuo=@protonmail.com>
=?utf-8?Q?Sylvain_D=C3=A9ve?= <sylvain.deve@protonmail.com> writes:
> # JSONB update for a single selected row and column.
> # 'column' and 'select_row' are determined with the parameters 'data' and 'path'.
> command = (
> f"""UPDATE MY_TABLE SET """
> f"""{column} = jsonb_merge({column}, %s) """
> f"""WHERE {select_row};"""
> )
> When called twice in a row, this call leads to the error (at "cur.execute"):
> psycopg2.errors.InternalError_: tuple concurrently updated
That error should be pretty hard to reach from user code, and certainly
two successive UPDATEs ought not have anything to do with it. I think
there is something you're not telling us about the context. Does this
table have any triggers, weird constraints, or the like? What is the
actual WHERE clause (ie, I wonder if you have simplified away some
relevant query detail)? What PG version is this exactly?
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, sylvain.deve@protonmail.com
Subject: Re: Update concurrency
In-Reply-To: <2377043.1640012857@sss.pgh.pa.us>
References: <-zxRtNEMT5cJjoFNR4LphpHl907G9wjMd-xShnDUyjZg5cgXZQpRdsNHe6OY96_8eyP9s0cyttLKUwv4FyRrirbUGeEoQe22M0lpaFJSGuo=@protonmail.com> <2377043.1640012857@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox