【问题标题】:Can we insert multiple rows using post api request in Big Query?我们可以在 Big Query 中使用 post api 请求插入多行吗?
【发布时间】:2016-01-21 18:34:40
【问题描述】:

我正在传递 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));
  });

【问题讨论】:

  • 您忘记设置唯一的 insertId。

标签: json upload http-post row google-bigquery


【解决方案1】:

我认为您的请求正文是错误的。您在“json”数组字段中有多个元素(实际上应该只是一个对象)。您确实应该在“行”字段中有多个元素。我认为您的请求应如下所示:

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'
        }
      }]
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-13
    相关资源
    最近更新 更多