2017-04-24 63 views
0

我有一個表X和另一個具有相同模式的表Y.當記錄插入X時,24小時後,它應該自動移動到Y. 我如何在postgres中實現這一點?postgres - 在插入24小時後將記錄從一個表移動到另一個表(同一個模式)

+0

我認爲這是不切實際的,從插入後24小時從一個表移到一個記錄到其他的你可以有X.expiry_date和過濾。如果當前日期高於X.expiry_date,則排定行,然後計劃作業,在運行時檢查該條件並將行移動到Y.您可以使用cron,調度程序...或Postgres擴展來計劃作業[如這一個](https://github.com/citusdata/pg_cron/)。 – andreim

回答

3

Postgres沒有這樣的自動化,你必須使用外部工具。例如,做一個cronjob運行的腳本,將做到這一點,smth likepslq -d dbname -c "begin; with d as (delete from x where ts < now() - '1 day'::interval returning *) insert into yselect * from d;; end;

相關問題