Re: BUG #17689: Two UPDATE operators in common table expressions (CTE) perform not as expected

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: eugene(dot)pliskin(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17689: Two UPDATE operators in common table expressions (CTE) perform not as expected
Date: 2022-11-18 17:05:57
Message-ID: 20221118170557.3ndokzwhilygtfq7@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On 2022-Nov-18, Marko Tiikkaja wrote:

> This is a documented limitation:
>
> > Trying to update the same row twice in a single statement is not
> > supported. Only one of the modifications takes place, but it is not
> > easy (and sometimes not possible) to reliably predict which one.
> > This also applies to deleting a row that was already updated in the
> > same statement: only the update is performed. Therefore you should
> > generally avoid trying to modify a single row twice in a single
> > statement. In particular avoid writing WITH sub-statements that
> > could affect the same rows changed by the main statement or a
> > sibling sub-statement. The effects of such a statement will not be
> > predictable.
>
> https://www.postgresql.org/docs/current/queries-with.html

I wonder if we should try to detect the case, and raise an error instead
of it resulting in undefined behavior.

--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2022-11-18 18:53:14 Re: BUG #17689: Two UPDATE operators in common table expressions (CTE) perform not as expected
Previous Message Marko Tiikkaja 2022-11-18 13:05:16 Re: BUG #17689: Two UPDATE operators in common table expressions (CTE) perform not as expected