Convert number to string in n1ql query output from Couchbase DB

Viewed 2120

I need the below value as a string in N1QL query output from Couchbase DB.

Current -

"cas": 1499937943452123136

Expected -

"cas": "1499937943452123136"

Cbq Query:

select meta().cas from sampledb where type = "PROD" and Id = 
"PROD_101"

Request your help.

2 Answers

To convert String to Number use to_string() method like given below example

enter image description here

If you want to convert string to number use TONUMBER() method like given below example

Query:

select sum(TONUMBER(installmentPremium)) TotalInstallmentPremium  from data
where installmentPremium > "10" and type_="ProductComponentOption" limit 100;

Result:

[
  {
    "TotalInstallmentPremium": 15757.470000000001
  }
]
Related