如果使用 N1QL 查询未找到结果,如何在 couchbase 中获取文件名(列名)?

How to get Filed name (Column Name) in couchbase if no result found using N1QL query?

我正在编写查询以在 Couchbase 中查找用户信息,我得到的结果是空数组,但我想要结果为空的字段,我尝试了几次,但我得不到这些字段的结果具有空值。如何获取header字段?

我的查询是

SELECT C.firstName AS `First Name`,
C.surName `Last Name`,
U.auditDetail.createTime AS `Date/Time of the Registration`
C.contactDetails.`email`.`value` AS `Email Address`,
C.contactDetails.`phone`.`value` AS ‘Phone Number`,
C.sex `Gender`,
C.dob AS `Data of Birth`,
ag.id AS `Referral Code`,
C.addressDetails.`office_new`.`zipcode` AS ‘Postal Code`,
C.addressDetails.`office_new.`city` AS `City`
FROM data C
UNNEST C.activeGroups AS ag
JOIN data_PH U ON U.loginld=C.contactDetails.`email`.`value`
WHERE U.type_='user'
AND C.type_= ‘customer`

结果:

{
  "results": []
}

当您执行查询时,签名具有 header 个字段。这就像描述 RDBMS 的列。

SELECT
  C.firstName AS `First Name`,
  C.surName `Last Name`,
  U.auditDetail.createTime AS `Date/Time of the Registration`,
  C.contactDetails.`email`.`value` AS `Email Address`,
  C.contactDetails.`phone`.`value` AS `Phone Number`,
  C.sex `Gender`,
  C.dob AS `Data of Birth`,
  ag.id AS `Referral Code`,
  C.addressDetails.`office_new`.`zipcode` AS `Postal Code`,
  C.addressDetails.`office_new`.`city` AS City
FROM default AS C
UNNEST C.activeGroups AS ag
JOIN default AS U ON U.loginld=C.contactDetails.`email`.`value`
WHERE U.type_="user"
      AND C.type_= "customer";

{
    "requestID": "c4a806b6-b3d7-4172-8b60-ebe195d00cef",
    "signature": {
        "City": "json",
        "Data of Birth": "json",
        "Date/Time of the Registration": "json",
        "Email Address": "json",
        "First Name": "json",
        "Gender": "json",
        "Last Name": "json",
        "Phone Number": "json",
        "Postal Code": "json",
        "Referral Code": "json"
    },
    "results": [
    ],
    "status": "success",
    "metrics": {
        "elapsedTime": "9.723082ms",
        "executionTime": "9.616195ms",
        "resultCount": 0,
        "resultSize": 0
    }
}

如果字段值为 MISSING,则字段将不会出现在 JSON 中以节省 Json 的大小。如果您真的想投影为默认值(“”),请使用 IFMISSING() 或 IFMISSINGORNULL() 或 IFNULL()

这只有在您有结果时才有效。零结果仍然给出空 objects.

 IFMISSING(C.firstName,"") AS `First Name`  --project MISSING field as empty string    
 IFMISSING(C.firstName, NULL) AS `First Name` --project MISSING field as NULL