RESTORE

Si applica a:segno di spunta sì Databricks SQL segno di spunta sì Databricks Runtime

Ripristina uno stato precedente di una tabella Delta. Il ripristino in un numero di versione precedente o un timestamp è supportato.

Questa pagina contiene informazioni dettagliate sull'uso della sintassi corretta con il RESTORE comando . Per altre indicazioni sull'esplorazione delle versioni delle tabelle delta Lake con questo comando, vedere Usare la cronologia delle tabelle Delta Lake.

Sintassi

RESTORE [ TABLE ] table_name [ TO ] time_travel_version

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

Parametri

  • table_name

    Identifica la tabella Delta da ripristinare. Il nome della tabella non deve usare una specifica temporale.

  • timestamp_expression può essere uno qualsiasi di:

    • '2018-10-18T22:15:12.013Z'ovvero una stringa di cui è possibile eseguire il cast a un timestamp
    • cast('2018-10-18 13:36:32 CEST' as timestamp)
    • '2018-10-18', ovvero una stringa di data
    • current_timestamp() - interval 12 hours
    • date_sub(current_date(), 1)
    • Qualsiasi altra espressione che è o può essere eseguita il cast a un timestamp
  • version è un valore long che può essere ottenuto dall'output di DESCRIBE HISTORY table_spec.

timestamp_expressionversion possono essere sottoquery.

Esempi

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