我们可以在 Big Query 中使用 post api 请求插入多行吗?
Can we insert multiple rows using post api request in Big Query?
我正在传递 2 JSON 的数组。但是只有第一个 JSON 的数据被插入到 Big Query 中。谁能告诉我哪里出错了?
var req = {
method: 'POST',
url: 'https://www.googleapis.com/bigquery/v2/projects/pid/datasets/dataid/tables/tabid/insertAll',
headers: {
'Authorization': token1,
'Content-Type': 'application/json',
'scope': 'https://www.googleapis.com/auth/bigquery'
},
json: {
"rows": [{
"json": [{
'code': 'X-new',
"remark": '',
'resulting_status': 'Cancelled'
}, {
'code': 'X-jdkdjk',
"remark": '',
'resulting_status': 'Required'
}]
}]
}
};
console.log(JSON.stringify(req.json.rows));
request(req, function(error, response, body) {
if (error)
debug("Error occurred from client's server" + error);
else
console.log("Response......" + JSON.stringify(response.body));
});
我认为你的请求正文是错误的。 "json" 数组字段中有多个元素(实际上应该只是一个对象)。 "rows" 字段中确实应该有多个元素。我认为您的请求应该如下所示:
json: {
"rows": [{
// optional insert id here.
"json": {
'code': 'X-new',
"remark": '',
'resulting_status': 'Cancelled'
}
}, {
// optional insert id here.
"json": {
'code': 'X-jdkdjk',
"remark": '',
'resulting_status': 'Required'
}
}]
}
我正在传递 2 JSON 的数组。但是只有第一个 JSON 的数据被插入到 Big Query 中。谁能告诉我哪里出错了?
var req = {
method: 'POST',
url: 'https://www.googleapis.com/bigquery/v2/projects/pid/datasets/dataid/tables/tabid/insertAll',
headers: {
'Authorization': token1,
'Content-Type': 'application/json',
'scope': 'https://www.googleapis.com/auth/bigquery'
},
json: {
"rows": [{
"json": [{
'code': 'X-new',
"remark": '',
'resulting_status': 'Cancelled'
}, {
'code': 'X-jdkdjk',
"remark": '',
'resulting_status': 'Required'
}]
}]
}
};
console.log(JSON.stringify(req.json.rows));
request(req, function(error, response, body) {
if (error)
debug("Error occurred from client's server" + error);
else
console.log("Response......" + JSON.stringify(response.body));
});
我认为你的请求正文是错误的。 "json" 数组字段中有多个元素(实际上应该只是一个对象)。 "rows" 字段中确实应该有多个元素。我认为您的请求应该如下所示:
json: {
"rows": [{
// optional insert id here.
"json": {
'code': 'X-new',
"remark": '',
'resulting_status': 'Cancelled'
}
}, {
// optional insert id here.
"json": {
'code': 'X-jdkdjk',
"remark": '',
'resulting_status': 'Required'
}
}]
}