Azure Cosmos DB 中的 OFFSET LIMIT 子句OFFSET LIMIT clause in Azure Cosmos DB

OFFSET LIMIT 子句是一个可选子句,可以跳过它,然后从查询中获取一些值。The OFFSET LIMIT clause is an optional clause to skip then take some number of values from the query. 必须在 OFFSET LIMIT 子句中指定 OFFSET 计数和 LIMIT 计数。The OFFSET count and the LIMIT count are required in the OFFSET LIMIT clause.

将 OFFSET LIMIT 与 ORDER BY 子句结合使用时,将通过跳过然后提取排序值来生成结果集。When OFFSET LIMIT is used in conjunction with an ORDER BY clause, the result set is produced by doing skip and take on the ordered values. 如果不使用 ORDER BY 子句,则会生成值的确定顺序。If no ORDER BY clause is used, it will result in a deterministic order of values.

语法Syntax

OFFSET <offset_amount> LIMIT <limit_amount>

参数Arguments

  • <offset_amount>

    指定查询结果应跳过的项数(整数)。Specifies the integer number of items that the query results should skip.

  • <limit_amount>

    指定查询结果应包含的项数(整数)Specifies the integer number of items that the query results should include

备注Remarks

必须在 OFFSET LIMIT 子句中同时指定 OFFSET 计数和 LIMIT 计数。Both the OFFSET count and the LIMIT count are required in the OFFSET LIMIT clause. 如果使用可选的 ORDER BY 子句,将会通过跳过排序值来生成结果集。If an optional ORDER BY clause is used, the result set is produced by doing the skip over the ordered values. 否则,查询将返回固定顺序的值。Otherwise, the query will return a fixed order of values. 目前,只有单个分区中的查询支持此子句,跨分区查询尚不支持它。Currently this clause is supported for queries within a single partition only, cross-partition queries don't yet support it.

示例Examples

例如,以下查询跳过第一个值并返回第二个值(按居住城市名称的顺序):For example, here's a query that skips the first value and returns the second value (in order of the resident city's name):

    SELECT f.id, f.address.city
    FROM Families f
    ORDER BY f.address.city
    OFFSET 1 LIMIT 1

其结果是:The results are:

    [
      {
        "id": "AndersenFamily",
        "city": "Seattle"
      }
    ]

以下查询跳过第一个值并返回第二个值(不排序):Here's a query that skips the first value and returns the second value (without ordering):

   SELECT f.id, f.address.city
    FROM Families f
    OFFSET 1 LIMIT 1

其结果是:The results are:

    [
      {
        "id": "WakefieldFamily",
        "city": "Seattle"
      }
    ]

后续步骤Next steps