When we select a number which is of length 7 digits, couchbase converts it to a Float. In the below case, we get the result as 1000000.0 instead of 1000000.
Code Sample
using (var bucket = _cluster.OpenBucket())
{
const string query = “SELECT 1000000 FROM DEFAULT”;
var result = bucket.Query(query);
console.writeline(result.rows[1]);
}
_cluster.Dispose();
Thanks for your reply. The problem is our query returns a JObject and in that we have a property of this 7 digit value which is getting converted to float.
Also I noted that
var result1 = bucket.Query(“SELECT 9999999 as MyValue FROM default”) - fails
var result1 = bucket.Query(“SELECT 9999999 as MyValue FROM default”) - Works
If I try
var result1 = bucket.Query(“SELECT 9999999 as MyValue FROM default”) - it returns with .0
Hi @srbhaski, what is the couchbase version? Do you see similar behavior with web-console/query-tab or cbq too?? We fixed a rounding issues with large ints (>15 digits or so) in 4.5.1. Do you want to try that build, or wait for 4.5.1 release?
There was a problem with large integers getting rounded because of conversion to floats in the query engine. I fixed this recently, and the fix should be available in 4.5.1.
In the current codebase, the query “SELECT 1000000 FROM default” returns a proper value 1000000, without adding a period.
Incidentally, this query only returns one row per document in the default bucket. If you always want just a single value, “SELECT 1000000” is legal N1QL and works.
What is the diff??
var result1 = bucket.Query(“SELECT 9999999 as MyValue FROM default”) - fails
var result1 = bucket.Query(“SELECT 9999999 as MyValue FROM default”) - Works
My post was marked for spam filter and when they released it, I think it got messed up. Anyhow what I meant was when I make the MyValue property as Int32, it fails, when I make it as Int64 it works and when I make it as dynamic, it works again as it converts it to Int64 automatically.
I have already got the answer from Johan for my issue. This one seems to be fixed in 4.5.1.