Re: [GENERAL] Using ctid in delete statement

Поиск
Список
Период
Сортировка
От Vick Khera
Тема Re: [GENERAL] Using ctid in delete statement
Дата
Msg-id CALd+dceP3cGhNajjPm8FmmuXZx+R=w74tGeVsYsZ55yy5f1omQ@mail.gmail.com
обсуждение исходный текст
Ответ на [GENERAL] Using ctid in delete statement  (pinker <pinker@onet.eu>)
Ответы Re: [GENERAL] Using ctid in delete statement  (pinker <pinker@onet.eu>)
Re: [GENERAL] Using ctid in delete statement  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general

On Wed, Feb 15, 2017 at 10:32 AM, pinker <pinker@onet.eu> wrote:
DELETE FROM table_name WHERE ctid = any ( array ( select tn.ctid from
table_name tn JOIN items i on tn.itemid=i.itemid WHERE tn.clock < extract (
epoch FROM now() - i.history * interval '10 day')::int + 6 limit 100));

Could I be sure that ctid will not change during the execution or will not
do any harm to other transactions?

It will be safe for two reasons: 1) your statement is running in its own implicit transaction, and 2) the rows selected from the subquery are visible to your transaction and thus will not have been "cleaned up" for re-use by any other transaction. So at worst you will try to delete the same object twice, which in this case is no harm, no foul. That ctid will not be able to point to some "other" object until your transaction is completed and the old rows are vacuumed.

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

Предыдущее
От: Leonardo M. Ramé
Дата:
Сообщение: [GENERAL] Foreign Data Wrapper for filesystem
Следующее
От: pinker
Дата:
Сообщение: Re: [GENERAL] Using ctid in delete statement