Cassandra Documentation

Version:

You are viewing the documentation for a prerelease version.

Creating columns with a single value (static column)

Static column values are shared among the rows in the partition. In a table that uses cassandra.apache.org//glossary.html#clustering-column[clustering columns], non-clustering columns can be declared static in the table definition. cassandra.apache.org//glossary.html#static-column[Static columns] are only static within a given partition.

In the following example, the flag column is static:

CREATE TABLE IF NOT EXISTS cycling.country_flag (
  country text,
  cyclist_name text,
  flag int STATIC,
  PRIMARY KEY (country, cyclist_name)
);
INSERT INTO cycling.country_flag (
  country, cyclist_name, flag
) VALUES (
  'Belgium', 'Jacques', 1
);

INSERT INTO cycling.country_flag (
  country, cyclist_name
) VALUES (
  'Belgium', 'Andre'
);

INSERT INTO cycling.country_flag (
  country, cyclist_name, flag
) VALUES (
  'France', 'Andre', 2
);

INSERT INTO cycling.country_flag (
  country, cyclist_name, flag
) VALUES (
  'France', 'George', 3
);
  • CQL

  • Result

SELECT *
FROM cycling.country_flag;
 country | cyclist_name | flag
---------+--------------+------
 Belgium |        Andre |    1
 Belgium |      Jacques |    1
  France |        Andre |    3
  France |       George |    3

(4 rows)

The following restrictions apply:

  • A table that does not define any clustering columns cannot have a static column. The table that does not have clustering columns has a one-row partition in which every column is inherently static.

  • A column designated to be the partition key cannot be static.

Use the DISTINCT keyword to select static columns. In this case, the database retrieves only the beginning (static column) of the partition.