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

时间:2018-04-13 13:31:21

标签: nosql couchbase

n1ql中是否有一个类似于mysql串联的函数,它允许我连接两个字段,例如:

select
firstName + " " + lastName
from table

2 个答案:

答案 0 :(得分:2)

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

  

N1QL提供连接字符串运算符。结果   连接运算符也是一个字符串。

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

<强>查询:

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

<强>结果:

{
  "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"
    }
  ]
}

答案 1 :(得分:0)

如果要串联,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"
    }
  ]
}