jack
jack

Reputation: 861

How to select partition for a table created in BigQuery?

I created a table using the "auto detect" in the UI. By doing that it created the table from Json file. enter image description here

Now I want the table to be partitioned by one of the TIMESTAMP columns.

How can I do that? The docs does not specify how to do it for an existed table. Can it be done from the UI? If not how can it be done with Python?

Upvotes: 1

Views: 419

Answers (1)

Elliott Brossard
Elliott Brossard

Reputation: 33705

You need to specify the partitioning as part of table creation; you cannot change it after the fact. What you can do is to create a new table with the schema and partitioning that you want, then reload the data. See the documentation for CREATE TABLE for the syntax to create a partitioned table. If you want to create the table without having to write out the column list, you can use a query like this:

CREATE TABLE dataset.newtable
PARTITION BY DATE(timestamp_column) AS
SELECT *
FROM dataset.existingtable
LIMIT 0

Note that if you remove the LIMIT 0, you can just create the table and copy the data at the same time, but you will incur a cost. Using LIMIT 0 and then reloading the data will be free.

Upvotes: 1

Related Questions