RESTORE
适用于: Databricks SQL Databricks Runtime
将增量表还原到早期状态。 支持还原到较早的版本号或时间戳。
本页包含有关使用 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 }
参数
-
标识要还原的 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
的输出中获取的 long 值。
timestamp_expression
和 version
都不能是子查询。
示例
-- 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