db_gg
db_gg

Reputation: 129

Create Bigquery partitioned table using Python and API

I would like to create a partitioned table in BigQuery from a Python script using client.create_table() but I get the error message

TypeError: create_table() got an unexpected keyword argument 'time_partitioning'`

Would be great if someone could tell me where I am going wrong.

This is the code I am using:

client = bigquery.Client.from_service_account_json('path/to/key')
...
data_ref = bigquery.DatasetReference(PROJECT_ID, DATASET_ID)
table_ref = bigquery.TableReference(data_ref, new_TABLE_ID)
table = bigquery.Table(table_ref, schema = SCHEMA) 
new_table = client.create_table(table, time_partitioning = True)

This is some documentation I used

Upvotes: 0

Views: 1698

Answers (1)

db_gg
db_gg

Reputation: 129

FYI solved with

client = bigquery.Client.from_service_account_json('path/to/key')
... 
data_ref = bigquery.DatasetReference(PROJECT_ID, DATASET_ID)
table_ref = bigquery.TableReference(data_ref, new_TABLE_ID)
table = bigquery.Table(table_ref, schema = SCHEMA)
table.partitioning_type = 'DAY' 
client.create_table(table)

Upvotes: 1

Related Questions