Astyanax Cassandra Double type precision
Asked Answered
R

1

6

I'm trying to get a Double value from a Cassandra table with a double type column. I've created the table in CQL3 syntax:

CREATE TABLE data_double (
    datetime timestamp,
    value double,
    primary key (datetime)
    );

I've inserted a row:

INSERT INTO data_double (datetime,  value) VALUES ('111111111', 123.456);  

When I do:

SELECT * from data_double;

I get that the value is 123.46

Why is the value rounded?

Thanks

Rhoden answered 9/5, 2014 at 20:39 Comment(0)
S
11

The cqlsh utility by default will only display 5 digits of precision for floating point numbers.

You can increase this by creating a cqlshrc file with contents like the following:

[ui]
float_precision = 10

The cqlsh docs page provides more details on the available options.

Update: The location of the cqlshrc file changed at some point in Cassandra. The new default location is ~/.cassandra/cqlshrc. You can also use a file in a different location with the --cqlshrc command-line option.

Sinuation answered 14/5, 2014 at 14:29 Comment(4)
Are you sure its . cqlshrc ? datastax referes to it as cqlshrc here docs.datastax.com/en/cql/3.3/cql/cql_reference/…Meliorism
@Meliorism thanks for pointing that out; the location did change somewhere along the way, so I've edited my answer to be more clear.Sinuation
so there's no way to this within the select statement?Assortment
@AFischbein no there isn't; the cqlshrc file is the only way I'm aware of. Keep in mind this is just the cqlsh shell behavior; when you run with your own application the driver will return the full precision of all floating values.Sinuation

© 2022 - 2024 — McMap. All rights reserved.