简体   繁体   English

从 csv 文件覆盖和 append 大查询表

[英]Overwrite and append big query table from csv file

I have an existing bq table with date, stock id and stock price columns.我有一个包含日期、股票 ID 和股票价格列的现有 bq 表。 Using bq load, I can either overwrite or append data from csv file.使用 bq load,我可以覆盖 csv 文件中的 append 数据。 Using csv file,使用 csv 文件,

  1. want to overwrite rows in bq table if date and stock id already exist (updating price),如果日期和股票 ID 已经存在(更新价格),想要覆盖 bq 表中的行,
  2. Else, want to append as new rows in bq table if if date and stock id does not exist in bq table否则,如果 bq 表中不存在日期和股票 ID,则希望将 append 作为 bq 表中的新行

In that scenario you would want to to a two step process.在那种情况下,您可能需要一个两步过程。

  1. load the data to a staging table.将数据加载到暂存表。
  2. Issue a MERGE statement, and define the when matched and not matched criteria as you needed.发出MERGE语句,并根据需要定义匹配条件和不匹配条件。

Documentation on the MERGE statement can be found here: https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement关于MERGE语句的文档可以在这里找到: https://cloud.google.com/bigquery/docs/reference/standard-sql/dml-syntax#merge_statement

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM