【发布时间】:2020-09-10 22:25:17
【问题描述】:
是否可以通过一条 SQL 指令更新 BigQuery 中的数据?
数据在一个数组中,每个元素必须更新 BigQuery 中的一行。
可以一次性发送所有信息还是我必须逐行更新?
在 BigQuery 中我有这张表:
| userID | Level |
|--------|-------|
| 01 | 2 |
| 02 | 2 |
| 03 | 3 |
| 04 | 3 |
在我的代码中我有这个数组:
[{
userID: 01,
newLevel: 5
},
{
userID: 02,
newLevel: 8
}
]
所以我需要用他们的新关卡数据更新用户 01 和 02。
这是我使用 nodejs 对 BigQuery 执行查询的代码:
const customQuery = async (query) => {
// Imports the Google Cloud client library
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = "your-project-id";
//console.log("query " + query)
// Modify this query however you need
const sqlQuery = query;
// Creates a client
const bigquery = new BigQuery();
// Query options list: https://cloud.google.com/bigquery/docs/reference/v2/jobs/query
const options = {
query: sqlQuery,
timeoutMs: 100000, // Time out after 100 seconds.
useLegacySql: false, // Use standard SQL syntax for queries.
};
// Runs the query
try {
var r = await bigquery.query(options);
//console.log("r: ", r)
} catch (err) {
console.log(err)
}
return r
}
【问题讨论】:
标签: javascript sql node.js google-bigquery sql-update