An archiving query - is it safe?

Поиск
Список
Период
Сортировка
От Herouth Maoz
Тема An archiving query - is it safe?
Дата
Msg-id 671916D8-6897-4D4F-940C-3FFF61D67513@unicell.co.il
обсуждение исходный текст
Ответы Re: An archiving query - is it safe?  (Vik Fearing <vik.fearing@dalibo.com>)
Список pgsql-sql
I have regular archiving scripts which traditionally did something like this

BEGIN TRANSACTION; INSERT INTO a__archive SELECT * FROM a WHERE <condition>; -- date range condition
 DELETE FROM a WHERE <condition>; -- same date range condition
COMMIT;

This is "classic" SQL. I'm thinking of changing this into something like:

WITH del AS ( DELETE FROM a WHERE <condition> RETURNING * )
INSERT INTO a__archive SELECT * FROM del;

As this would only access table "a" once, deleting and returning the records in the same access, which I believe will
bemore efficient. 

Is this safe to do? Is there any danger of losing data? Is it atomic?



Thank you,
Herouth


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

Предыдущее
От: Brice André
Дата:
Сообщение: Re: Index on multiple columns VS multiple index
Следующее
От: Vik Fearing
Дата:
Сообщение: Re: An archiving query - is it safe?