Write query results from a table to a partitioned - clustered table in BigQuery

Viewed 129

I have temp table where data is loaded from a cloud storage and a main table which is partitioned by "tdate" and clustered by "serid"

tdate and serid columns exists in temp table and tdate is like this format "YYYY-MM-DD" and serid is integer number

I know how to write query results like below.

CREATE TABLE `[project].[dataset].[dest table]`
PARTITION BY tdate
CLUSTER BY serid 
AS
SELECT * FROM `[project].[dataset].[table]`; 

Can somebody tell me how can i achieve this to append data from temp table to main table using bq command or in python

p:s Im new to gcp and just started today

1 Answers

Did you try to use script? I mean to run several queries in the same call separated by semicolon ;

CREATE TABLE IF NOT EXISTS `[project].[dataset].[dest table]` (
  # Add your schema here
  tdate date,
  serid numeric
)
  PARTITION BY tdate
  CLUSTER BY serid;
INSERT INTO `[project].[dataset].[dest table]` SELECT * FROM `[project].[dataset].[table]`;
Related