It is possible to update data in BigQuery with one SQL instruction?
Data are in an array and each element must to update one row in BigQuery.
It is possible send all the information in one shot or I have to update rows one by one?
In BigQuery I have this table:
| userID | Level |
|--------|-------|
| 01 | 2 |
| 02 | 2 |
| 03 | 3 |
| 04 | 3 |
and in my code I have this array:
[{
userID: 01,
newLevel: 5
},
{
userID: 02,
newLevel: 8
}
]
So I need to UPDATE users 01 and 02 with their new levels data.
here is my code for executing queries to BigQuery using nodejs:
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
}