Jack Douglas

I was expecting both `bar` and `baz` to be `20`, what is going on?
Top Answer
Jack Douglas
It [is documented](https://www.postgresql.org/docs/12/queries-with.html#QUERIES-WITH-MODIFYING) that this is not supported for data-modifying statements in `with` clauses:

> 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.

The docs go on to say:

> 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.

You'll need to rewrite your updates so each row only gets changed in at most one sub-statement, OR in the main statement:


This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.