Skip to content

Query error when trying to insert in partitioned table #4073

Closed
@Kayrnt

Description

@Kayrnt

Using following code to write in an existing daily partitioned table:

bigquery_client = bigquery.Client(project=self.project_id)
dataset = bigquery_client.dataset(self.destination_dataset)
destination_table_with_day = "table$20170927"
sql = """
        #standardSQL
        ...
       """

table = dataset.table(destination_table_with_day)
table.partitioning_type = "DAY"
query = client.run_async_query(str(uuid.uuid4()), sql)
query.destination = table
query.write_disposition = 'WRITE_TRUNCATE'
query.begin()
query.result()

I expected similar result as the CLI with
bq query --use_legacy_sql=false --replace --destination_table 'dataset.table$20170927' "..." which works flawlessly

But it returned ERROR - 400 Partitioning specification must be provided in order to create partitioned table

I suspect that some parameters are missing that would result in this error such as https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.query.timePartitioning.type

I'm not really that fluent in Python so I couldn't find out that it's the problem is the way I use the SDK or in the SDK.

I didn't find any sample related on that case inside https://github.com/GoogleCloudPlatform/python-docs-samples but I saw #2729 that could be related somehow.

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the BigQuery API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions