15.数组操作和切片

数组切片是指使用一个数组的子集。

下边的查询将返回所有的children之间的下表从0,取2的数据。

N1QL还支持数组函数,如ARRAY_PREPEND ,ARRAY_APPEND, ARRAY_CONCAT

Query:

SELECT children[0:2] 
    FROM tutorial 
        WHERE children[0:2] IS NOT MISSING

注意:从输出结果可以看出children为null的情况也进行了匹配

结果:

{
  "results": [
    {
      "$1": [
        {
          "age": 17,
          "fname": "Aiden",
          "gender": "m"
        },
        {
          "age": 2,
          "fname": "Bill",
          "gender": "f"
        }
      ]
    },
    {
      "$1": [
        {
          "age": 17,
          "fname": "Xena",
          "gender": "f"
        },
        {
          "age": 2,
          "fname": "Yuri",
          "gender": "m"
        }
      ]
    },
    {
      "$1": null
    },
    {
      "$1": [
        {
          "age": 17,
          "fname": "Abama",
          "gender": "m"
        },
        {
          "age": 21,
          "fname": "Bebama",
          "gender": "m"
        }
      ]
    }
  ]
}

Last updated

Was this helpful?