Can I create a BigQuery table / schema without populating it with data?
Can I create a table schema without pre-filling the data? Google python client is preferred. Google documentation doesn't seem to provide a clear yes or no answer. They suggest creating a table with a query, but this is unintuitive and, again, not documented:
+3
source to share
1 answer
In python you can run an insert job on the table API endpoint and create an empty table as it is documented here you need to supply the 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 for copying content into named arguments
Check out other python + bigquery questions .
+6
source to share