在Couchbase DB的n1ql查询输出中将数字转换为字符串

时间:2017-07-13 13:33:37

标签: couchbase n1ql

我需要以下值作为Couchbase DB的N1QL查询输出中的字符串。

当前 -

"cas": "1499937943452123136"

预期 -

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

Cbq查询:

$params = array(
            'a' => 'foo',
            'b' => 'bar'
        );
$output = $this->request('GET', 'my_controller/my_function', $params);

请求帮助。

此致 Emraan。

2 个答案:

答案 0 :(得分:2)

使用to_string函数。

{{1}}

您使用的是什么版本的Couchbase?

答案 1 :(得分:0)

要将String转换为数字,请使用 to_string()方法,如下例所示

enter image description here

如果要将字符串转换为数字,请使用 TONUMBER()方法,如下面的示例所示

查询:

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

结果:

[
  {
    "TotalInstallmentPremium": 15757.470000000001
  }
]