我有一个表格,需要根据 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/