RESTORE

適用於:檢查標示為是 Databricks SQL 檢查標示為是 Databricks Runtime

將 Delta 數據表還原至先前的狀態。 支援還原至舊版號碼或時間戳。

此頁面包含搭配命令使用正確語法 RESTORE 的詳細數據。 如需使用此命令流覽 Delta Lake 資料表版本的詳細資訊,請參閱 使用 Delta Lake 資料表歷程記錄

語法

RESTORE [ TABLE ] table_name [ TO ] time_travel_version

time_travel_version
 { TIMESTAMP AS OF timestamp_expression |
   VERSION AS OF version }

參數

  • table_name

    識別要還原的 Delta 數據表。 數據表名稱不得使用 時態規格

  • timestamp_expression 可以是下列任一項:

    • '2018-10-18T22:15:12.013Z',也就是可以轉換成時間戳的字串
    • cast('2018-10-18 13:36:32 CEST' as timestamp)
    • '2018-10-18',也就是日期字串
    • current_timestamp() - interval 12 hours
    • date_sub(current_date(), 1)
    • 任何其他可轉換成時間戳的表達式
  • version 是一個長值,可從的 DESCRIBE HISTORY table_spec輸出取得。

versiontimestamp_expression都不能是子查詢。

範例

-- Restore the employee table to a specific timestamp
> RESTORE TABLE employee TO TIMESTAMP AS OF '2022-08-02 00:00:00';
 table_size_after_restore num_of_files_after_restore num_removed_files num_restored_files removed_files_size restored_files_size
                      100                          3                 1                  0                574                   0

-- Restore the employee table to a specific version number retrieved from DESCRIBE HISTORY employee
> RESTORE TABLE employee TO VERSION AS OF 1;
 table_size_after_restore num_of_files_after_restore num_removed_files num_restored_files removed_files_size restored_files_size
                      100                          3                 1                  0                574                   0

-- Restore the employee table to the state it was in an hour ago
> RESTORE TABLE employee TO TIMESTAMP AS OF current_timestamp() - INTERVAL '1' HOUR;
 table_size_after_restore num_of_files_after_restore num_removed_files num_restored_files removed_files_size restored_files_size
                      100                          3                 1                  0                574                   0