YugaByte YugaByte
PRODUCT
YugaByte DB Enterprise Edition Compare
SOLUTIONS

Use Cases

Distributed OLTP Apps Fast Data Infrastructure

Deployment Options

Microservices & Containers Multi-Region & Multi-Cloud

Roles

App Development Cloud Operations

Industries

Software-as-a-Service Financial Services Internet of Things E-Commerce
DOCS
Install Explore Develop FAQ
RESOURCES

Meet Us

Events Online Talks

Request Help

GitHub Forum Gitter
ABOUT
Team Careers In the News Contact Us
BLOG
Download

Docs

  • Introduction
    • Overview
    • Core Features
    • Benefits
  • Quick Start
    • 1. Install YugaByte DB
    • 2. Create Local Cluster
    • 3. Test Cassandra API
    • 4. Test Redis API
    • 5. Run Sample Apps
  • Explore
    • 1. Linear Scalability
    • 2. Fault Tolerance
    • 3. ACID Transactions
    • 4. Secondary Indexes
    • 5. Auto Sharding
    • 6. Auto Rebalancing
    • 7. Tunable Reads
  • Develop
    • Client Drivers
      • Java
      • NodeJS
      • Python
    • Learn
      • 1. SQL vs NoSQL
      • 2. Data Modelling
      • 3. ACID Transactions
      • 4. Aggregations
      • 5. Batch Operations
    • Ecosystem Integrations
      • Apache Spark
      • JanusGraph
      • KairosDB
    • Real World Examples
      • E-Commerce App
      • IoT Fleet Management
  • Deploy
    • Private DC
    • Kubernetes
      • Local SSD
    • Public Clouds
      • Amazon Web Services
      • Google Cloud Platform
      • Microsoft Azure
    • Enterprise Edition
      • 1. Initial Setup
      • 2. Install Admin Console
      • 3. Configure Cloud Providers
  • Manage
    • Enterprise Edition
      • Create Universe
      • Edit Universe
      • Edit Config Flags
      • Upgrade Universe
      • Delete Universe
    • Diagnostics Reporting
  • Troubleshoot
    • Troubleshooting Overview
    • Cluster Level Issues
      • Cassandra Connection Issues
      • Redis Connection Issues
    • Node Level Issues
      • Check Processes
      • Inspect Logs
      • System Stats
    • Enterprise Edition
      • Troubleshoot Universes
  • Architecture
    • Basics
      • Single Node
      • Universe, YB-TServer, YB-Master
      • Sharding
      • Replication
      • Persistence
      • Query Layer
      • Acknowledgements
    • Core Functions
      • Universe Creation
      • Table Creation
      • Write IO Path
      • Read IO Path
      • High Availability
    • Transactions
      • Isolation Levels
      • Single Row Transactions
      • Distributed Transactions
      • Transactional IO Path
  • Comparisons
    • Apache Cassandra
    • MongoDB
    • Redis
    • Azure Cosmos DB
    • Google Cloud Spanner
    • Apache HBase
  • API Reference
    • Apache Cassandra
      • ALTER TABLE
      • CREATE INDEX
      • CREATE KEYSPACE
      • CREATE TABLE
      • CREATE TYPE
      • DROP KEYSPACE
      • DROP TABLE
      • DROP TYPE
      • USE
      • INSERT
      • SELECT
      • UPDATE
      • DELETE
      • TRANSACTION
      • TRUNCATE
      • Simple Value
      • Subscript
      • Function Call
      • Operator Call
      • BLOB
      • BOOLEAN
      • MAP
      • FROZEN
      • INET
      • Integer
      • Non-integer
      • TEXT
      • Date & Time
      • UUID & TIMEUUID
    • Redis
      • APPEND
      • AUTH
      • CONFIG
      • DEL
      • ECHO
      • EXISTS
      • FLUSHALL
      • FLUSHDB
      • GET
      • GETRANGE
      • GETSET
      • HDEL
      • HEXISTS
      • HGET
      • HGETALL
      • HKEYS
      • HLEN
      • HMGET
      • HMSET
      • HSET
      • HSTRLEN
      • HVALS
      • INCR
      • MGET
      • MSET
      • ROLE
      • SADD
      • SCARD
      • SET
      • SETRANGE
      • SISMEMBER
      • SMEMBERS
      • SREM
      • STRLEN
      • TSADD
      • TSGET
      • TSRANGEBYTIME
      • TSREM
      • TSCARD
      • TSLASTN
      • ZADD
      • ZCARD
      • ZRANGEBYSCORE
      • ZREM
      • ZREVRANGE
  • Admin Reference
    • yb-ctl
    • yb-docker-ctl
    • docker-compose
    • yb-master
    • yb-tserver
  • FAQs
    • Product
    • Architecture
    • Enterprise Edition
    • Cassandra API
API Reference Apache Cassandra

Integer Types

    • Synopsis
    • Syntax
    • Semantics
      • Counter DataType
    • Examples
      • Using integer datatypes
      • Using COUNTER datatype
    • See Also

Synopsis

There are several different datatypes for integers of different value ranges. Integers can be set, inserted, incremented, and decremented while COUNTER can only be incremented or decremented. We’ve extend Apache Cassandra to support increment and decrement operator for integer datatypes.

DataType Min Max
TINYINT -128 127
SMALLINT -2,147,483,648 2,147,483,647
INT or INTEGER -32,768 32,767
BIGINT -2,147,483,648 2,147,483,647
COUNTER -2,147,483,648 2,147,483,647

Syntax

The following keywords are used to specify a column of type integer for different constraints including its value ranges.

type_specification ::= TINYINT | SMALLINT | INT | INTEGER | BIGINT | COUNTER

integer_literal ::= [ + | - ] digit [ { digit | , } ... ]

Semantics

  • Columns of type TINYINT, SMALLINT, INT, INTEGER, or BIGINT can be part of the PRIMARY KEY.
  • Values of different integer datatypes are comparable and convertible to one another.
  • Values of integer datatypes are convertible but not comparable to floating point number.
  • Values of floating point datatypes are not convertible to integers.

Counter DataType

COUNTER is an alias of BIGINT but has additional constraints.

  • Columns of type COUNTER cannot be part of thePRIMARY KEY.
  • If a column is of type COUNTER, all non-primary-key columns must also be of type COUNTER.
  • Column of type COUNTER cannot be set or inserted. They must be incremented or decremented.
  • If a column of type COUNTER is NULL, its value is replaced with zero when incrementing or decrementing.

Examples

Using integer datatypes

cqlsh:example> CREATE TABLE items(id INT PRIMARY KEY, item_count BIGINT);
cqlsh:example> INSERT INTO items(id, item_count) VALUES(1, 1);
cqlsh:example> INSERT INTO items(id, item_count) VALUES(2, 2);
cqlsh:example> UPDATE items SET item_count = 5 WHERE id = 1;
cqlsh:example> UPDATE items SET item_count = item_count + 1 WHERE id = 2;
cqlsh:example> SELECT * FROM items;
 id | item_count
----+------------
  2 |          3
  1 |          5

Using COUNTER datatype

cqlsh:example> CREATE TABLE item_counters(id INT PRIMARY KEY, item_counter COUNTER);

For counter type, null values are treated as 0.

cqlsh:example> UPDATE item_counters SET item_counter = item_counter + 1 WHERE id = 1;
cqlsh:example> SELECT * FROM item_counters;
 id | item_counter
----+--------------
  1 |            1

See Also

Data Types

INET Type
Non-integer Numbers
YugaByte

SUBSCRIBE TO NEWS

The latest news, tips, blog posts, and resources.

Copyright © 2017-2018 YugaByte, Inc. All rights reserved.

Apache and Apache Cassandra are trademarks of the Apache Software Foundation in the United States and/or other countries. Redis and the Redis logo are the trademarks of Salvatore Sanfilippo in the United States and other countries. No endorsement by these organizations is implied by the use of these marks.