许多更新后恢复列值

时间:2017-10-31 07:54:54

标签: sql postgresql

如何在表上进行多次更新后返回discount_price列的旧值?

以下是我的一些更新

UPDATE products SET discount_price = discount_price + 0.95
   WHERE discount_price >= 1  AND discount_price <= 10;

UPDATE products SET discount_price = discount_price + 1.5
   WHERE discount_price >= 10 AND discount_price <= 30;

UPDATE products SET discount_price = discount_price + 2
   WHERE discount_price >= 30 AND discount_price <= 50;

UPDATE products SET discount_price = discount_price + 3
   WHERE discount_price >= 50 AND discount_price <= 100;

1 个答案:

答案 0 :(得分:0)

如果您在交易中应用更改,则可以使用ROLLBACK取消交易以撤消更改。

提交事务后无法撤消UPDATE

要恢复过去的数据,您必须从备份恢复数据库。

如果您是PostgreSQL专家并且VACUUM尚未运行,您可以使用pageinspect contrib模块从表中获取旧数据。