【问题标题】:How to fetch all the batches for a query at one go using stored proc in azure SQL db?如何使用 Azure SQL db 中的存储过程一次性获取查询的所有批次?
【发布时间】:2019-03-28 11:40:10
【问题描述】:

我正在尝试检查集合中是否存在重复项。存储过程和天蓝色数据库的新手,所以现在我正在尝试计算不同的条目。如果 count distinct (column name) = count (column name),则没有重复项,因此我正在尝试为此编写一个存储过程。但 azure 一次只能检索 100 个文档。我需要对所有可用批次进行计数。

我能够获得不同条目的计数,但它显示了检索到的第一批的计数 - 这是 100。我需要所有批次的计数。

function sample(prefix) {
    var collection = getContext().getCollection();

    var isAccepted = collection.queryDocuments(
        collection.getSelfLink(),
        'SELECT DISTINCT VALUE r.column FROM root r',
    function (err, feed, options) {
        if (err) throw err;
        if (!feed || !feed.length) {
            var response = getContext().getResponse();
            response.setBody('no docs found');
        }
        else {
            var response = getContext().getResponse();
            response.setBody(JSON.stringify(feed.length));
        }
    });

    if (!isAccepted) throw new Error('The query was not accepted by the server.');
}

我希望输出能够计算集合中不同的条目。应该是103,实际是100,是azure一次性检索到的数字。

【问题讨论】:

    标签: javascript sql stored-procedures azure-sql-database


    【解决方案1】:

    queryDocuments 的 FeedOptions pageSize 属性的默认值为 100,这可能是问题的原因。请尝试将值设置为 -1。以下存储过程在我这边运行良好,请参考。

    function getall(){
     var context = getContext();
      var response = context.getResponse();
      var collection = context.getCollection();
      var collectionLink = collection.getSelfLink();
    
      var filterQuery = 'SELECT * FROM c';
    
      collection.queryDocuments(collectionLink, filterQuery, {pageSize:-1 },
        function(err, documents) {
          response.setBody(response.getBody() + JSON.stringify(documents));
        }
      );
    }
    

    希望对你有帮助。

    【讨论】:

    • 如果有帮助,请接受作为答案。它将帮助其他有相同 ASK 的人。
    猜你喜欢
    • 1970-01-01
    • 2010-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多