google-apps-script - 大查询 : Appending to existing table with Apps Script

标签 google-apps-script google-sheets google-bigquery

我有一个表格,需要根据 Google 表格中的新数据添加更多记录。

我看到了如何使用 union 来完成它,这意味着运行

从(SELECT * from table)中选择 *,(从 temp_table_from_sheets 中选择 *)

即:查询旧表,新表。删除旧表并将查询结果保存为旧表。

但必须可以追加而不是仅 BigQuery.Jobs.insert

你能帮帮我吗?

编辑 - 解决方案

得到下面的答案后,我用谷歌搜索了很多,最终在 Apps Script 中找到了以下解决方案:

var sql = 'select ...'
var projectId = '...'
var datasetId = '...'
var tableId = '...'

var job = {
    configuration: {
      query: {
        query: sql,
        writeDisposition:'WRITE_APPEND',
        destinationTable: {
          projectId: projectId,
          datasetId: datasetId,
          tableId: tableId
        }       
      }
    }
  };

   var queryResults = BigQuery.Jobs.insert(job, projectId)

最佳答案

来自 BigQuery API Basics - Managing Tables :

Appending data

You can load additional data into a table either from source files or by appending query results. Note that the schema of the loaded data must match the schema of the existing table, but you can update the schema before appending.

...

To append data from a query result:

Run an asynchronous query, pass in the name of your existing table, and set writeDisposition=WRITE_APPEND.

关于google-apps-script - 大查询 : Appending to existing table with Apps Script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38292665/

相关文章:

mysql - 每 20 次迭代更新 SQL 中的行

google-apps-script - 自动化谷歌分析报告

google-apps-script - 如何在 URL 中包含数据以供 Google Apps Script 网络应用程序读取?

javascript - 根据谷歌表格中缺失的数据创建表单

google-apps-script - 在 Google 表格中插入新行或编辑行时添加时间戳

google-apps-script - 提交与商品标签Google表单(Google脚本)不同的值

google-bigquery - 无法使用 Java Bigquery Client API 在 BigQuery 中写入日期

java - Google 云 Bigquery UDF 限制

google-apps-script - 从 Gmail 原始内容解析 inlineImages

gmail - 将 Evernote 笔记导出到 Kindle(通过 Gmail?)