如何连接 n1ql 中的两个字段?

How do I concatenate two fields in n1ql?

n1ql 中是否有类似于 mysql 的串联功能,可以让我串联两个字段,例如:

select
firstName + " " + lastName
from table

来自 N1QL 文档 (https://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/stringops.html):

N1QL provides the concatenation string operator. The result of the concatenation operator is also a string.

expression || expression    The following example shows concatenation of two strings.

Query:

SELECT fname || " " || lname AS full_name
FROM tutorial    

Result:

{
  "results": [
    {
      "full_name": "Dave Smith"
    },
    {
      "full_name": "Earl Johnson"
    },
    {
      "full_name": "Fred Jackson"
    },
    {
      "full_name": "Harry Jackson"
    },
    {
      "full_name": "Ian Taylor"
    },
    {
      "full_name": "Jane Edwards"
    }
  ]
}

如果要连接 Integers 应先将其转换为 TO_STRING:

SELECT 'My name is ' || fname  || ' and my age is ' || TO_STRING(30) || ' years old' AS age
FROM app 



{
  "results": [
    {
      "age": "My name is Dave and my age is 30 years old"
    },
    {
      "age": "My name is Earl and my age is 30 years old"
    },
    {
      "age": "My name is Fred and my age is 30 years old"
    },
    {
      "age": "My name is Harry and my age is 30 years old"
    },
    {
      "age": "My name is Ian and my age is 30 years old"
    },
    {
      "age": "My name is Jane and my age is 30 years old"
    }
  ]
}