Untitled

 avatar
unknown
plain_text
2 years ago
985 B
4
Indexable
from google.cloud import bigquery

def copy_tables(project_id, source_dataset_id, destination_dataset_id, table_list):
    client = bigquery.Client(project=project_id)
    
    for table_name in table_list:
        source_table_ref = bigquery.DatasetReference(project_id, source_dataset_id).table(table_name)
        destination_table_ref = bigquery.DatasetReference(project_id, destination_dataset_id).table(table_name)

        copy_job = client.copy_table(source_table_ref, destination_table_ref)
        copy_job.result()  # Wait for the job to complete.

        print(f"Copied table {table_name} from {source_dataset_id} to {destination_dataset_id}")

if __name__ == '__main__':
    project_id = 'your_project_id'
    source_dataset_id = 'source_dataset'
    destination_dataset_id = 'destination_dataset'
    tables_to_copy = ['table1', 'table2', 'table3']  # Add table names to this list.

    copy_tables(project_id, source_dataset_id, destination_dataset_id, tables_to_copy)
Editor is loading...