将查询结果从表写入到BigQuery中的分区集群表

时间:2020-08-18 16:25:12

标签: python google-cloud-platform google-bigquery

我有一个临时表,其中的数据是从云存储中加载的,还有一个主表,该主表由“ tdate” 分区,并由“ serid

聚集 临时表中存在

tdate serid 列,并且tdate类似于这种格式“ YYYY-MM-DD”,而serid是整数

我知道如何编写如下查询结果。

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

有人可以告诉我如何使用 bq 命令或在 python

中将临时表中的数据追加到主表中

p:s我是gcp的新手,今天才开始

1 个答案:

答案 0 :(得分:3)

您尝试使用script吗?我的意思是要在同一调用中运行多个查询,并用分号隔开;

                         EXPLANATION
--------------------------------------------------------------------------------
  ^                        the beginning of the string
--------------------------------------------------------------------------------
  The thing is             'The thing is'
--------------------------------------------------------------------------------
  .*                       any character except \n (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  \b                       the boundary between a word char (\w) and
                           something that is not a word char
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    S                        'S'
--------------------------------------------------------------------------------
    \d                       digits (0-9)
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  (?!                      look ahead to see if there is not:
--------------------------------------------------------------------------------
    .*                       any character except \n (0 or more times
                             (matching the most amount possible))
--------------------------------------------------------------------------------
    \b                       the boundary between a word char (\w)
                             and something that is not a word char
--------------------------------------------------------------------------------
    (?:                      group, but do not capture:
--------------------------------------------------------------------------------
      blue                     'blue'
--------------------------------------------------------------------------------
     |                        OR
--------------------------------------------------------------------------------
      red                      'red'
--------------------------------------------------------------------------------
    )                        end of grouping
--------------------------------------------------------------------------------
    \b                       the boundary between a word char (\w)
                             and something that is not a word char
--------------------------------------------------------------------------------
  )                        end of look-ahead