Re: Joins of data-modifying CTE with the target table

Поиск
Список
Период
Сортировка
От Alex Bolenok
Тема Re: Joins of data-modifying CTE with the target table
Дата
Msg-id CAMX8OqKQqHAJmP=Ph28W_o=2En+BqRjJ4WrWf3ovTd2m8SaSTw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Joins of data-modifying CTE with the target table  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Joins of data-modifying CTE with the target table  (Adrian Klaver <adrian.klaver@aklaver.com>)
Re: Joins of data-modifying CTE with the target table  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
To reiterate, I (I personally) get why it's not working, but the documentation is something that is intended for people who don't.

Technically, anyone can deduce it from reading the documentation thoroughly enough, but do we need the documentation to be as terse as possible?

To answer your question, by "explicitly" I mean mentioning this very pattern, where you join the returned id with the target table. People often try to use this pattern for queries like "add an item to the order in a CTE, select the order total in the main query", and often don't notice that the order total doesn't include the new item until it hits production.

ср, 19 апр. 2023 г. в 11:46, Tom Lane <tgl@sss.pgh.pa.us>:
Alex Bolenok <quassnoi@gmail.com> writes:
> I get why it's not working (because the statement is not allowed to see the
> tuples with its own cmin), but I was wondering if it was worth it at least
> to spell it out explicitly in the documentation.

What's not explicit about this?

    The sub-statements in WITH are executed concurrently with each other
    and with the main query. Therefore, when using data-modifying
    statements in WITH, the order in which the specified updates actually
    happen is unpredictable. All the statements are executed with the same
    snapshot (see Chapter 13), so they cannot “see” one another's effects
    on the target tables.

                        regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Joins of data-modifying CTE with the target table
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: Joins of data-modifying CTE with the target table