RESTORE

適用対象:「はい」のチェック マーク Databricks SQL check marked yes 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 の出力から取得できる long 型の値です。

timestamp_expressionversion もサブクエリにすることはできません。

-- 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