Possible To Create Bigquery Table/schema Without Populating With Data?
Is it possible to create a Table schema without first populating it with data? Preferably using Google's python client. Google's documentation does not seem to provide a clear yes
Solution 1:
In python you can run an insert job on the tables API endpoint and that will create an empty table as it's documented here you need to supply a TableResource
project_id = <my project>
dataset_id = <my dataset>
table_id = 'table_001'
dataset_ref = {'datasetId': dataset_id,
'projectId': project_id}
table_ref = {'tableId': table_id,
'datasetId': dataset_id,
'projectId': project_id}
schema_ref = {<schema comes here>}
table = {'tableReference': table_ref,
'schema': schema_ref}
table = bigquery.tables().insert(
body=table, **dataset_ref).execute(http)
**dataset_ref is a python trick to copy the contents to named arguments
Browse other python + bigquery questions.
Post a Comment for "Possible To Create Bigquery Table/schema Without Populating With Data?"