Arithmetic operators

CQL supports these arithmetic operators:

Operator Description

-

Use the minus symbol for either the unary negate operand or subtraction.

+

Use the plus symbol for addition.

*

Use the asterisk symbol for multiplication.

/

Use the forward slash symbol for division.

%

Use the percent symbol to return the remainder from division.

The *, /, and % operators have a higher precedence than the + and - operators. Higher precedence operators are evaluated before lower precedence operators. If two operators in an expression have the same precedence, they are evaluated from left to right based on the operator position in the expression.

Return types

The return type of an arithmetic expression is based on the types of the input operands. In the following table, left and right refer to the type of the operand on the left and right of the operator. For example, in the expression a + b, a is the left operand and b is the right operand; if a is an int operand and b is a float operand, a float is returned.

left/right

tinyint

smallint

int

bigint

counter

float

double

varint

decimal

tinyint

tinyint

smallint

int

bigint

bigint

float

double

varint

decimal

smallint

smallint

smallint

int

bigint

bigint

float

double

varint

decimal

int

int

int

int

bigint

bigint

float

double

varint

decimal

bigint

bigint

bigint

bigint

bigint

bigint

double

double

varint

decimal

counter

bigint

bigint

bigint

bigint

bigint

double

double

varint

decimal

float

float

float

float

double

double

float

double

decimal

decimal

double

double

double

double

double

double

double

double

decimal

decimal

varint

varint

varint

varint

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

decimal

Dates and times

A time duration can be added (+) or subtracted (-) from a timestamp or a date to create a new timestamp or date. For example, the following query returns cycling races that occur one day before the supplied date:

SELECT * FROM cycling.race_times
  WHERE race_date = '2017-04-15' - 1d;

Multiple columns

Multiple columns can be used in an expression, as shown in the following queries:

SELECT (emp_id + dept_id) / age FROM cycling.mechanic;

Non-arithmetic operators

CQL supports the following non-arithmetic operators:

Operator Description

CONTAINS

Use to find a value in a collection .

CONTAINS

Use to find a key in a map collection.

IN

Use to find a value included in the specified list of values.

LIKE

Use to find a value that matches a pattern if a fuzzy search is enabled.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com