建立 BigQuery 資料表的快照

示範如何從 BigQuery 代管資料表建立快照資料表。

程式碼範例

Python

在試行這個範例之前,請先按照 BigQuery 快速入門導覽課程:使用用戶端程式庫中的 Python 設定說明進行操作。詳情請參閱 BigQuery Python API 參考說明文件

如要向 BigQuery 進行驗證,請設定應用程式預設憑證。 詳情請參閱「設定用戶端程式庫的驗證機制」。

from google.cloud import bigquery

# TODO(developer): Set table_id to the ID of the table to create.
source_table_id = "your-project.your_dataset.your_table_name"
snapshot_table_id = "your-project.your_dataset.snapshot_table_name"

# Construct a BigQuery client object.
client = bigquery.Client()
copy_config = bigquery.CopyJobConfig()
copy_config.operation_type = bigquery.OperationType.SNAPSHOT

copy_job = client.copy_table(
    sources=source_table_id,
    destination=snapshot_table_id,
    job_config=copy_config,
)
copy_job.result()

print("Created table snapshot {}".format(snapshot_table_id))

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽器