Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have null values in clustering columns of a primary key?

Tags:

cassandra

So I have a table and I want to make a composite primary key: one partition key and several clustering columns. However these columns are not strictly speaking always populated, so some rows may have null values. Is this allowed in Cassandra? To have clustering columns with null values?

like image 506
Mnemosyne Avatar asked Jun 16 '17 00:06

Mnemosyne


People also ask

Can a primary key column contain NULL values?

A primary key defines the set of columns that uniquely identifies rows in a table. When you create a primary key constraint, none of the columns included in the primary key can have NULL constraints; that is, they must not permit NULL values.

Can clustering key be NULL?

Cassandra does not allow null clustering key values. If you really need "no value" for some reason, then use an empty string OR some other special literal value like 'UNDEFINED' to cluster those together. Show activity on this post. In regular (non-compact) tables, clustering keys cannot have missing columns.

Can clustering column be NULL?

because you cannot have a NULL value for any columns in the PRIMARY KEY (see Defining a partition key with clustering columns): A NULL value cannot be inserted into a PRIMARY KEY column. This restriction applies to both partition keys and clustering columns.

Why NULL values are not allowed in primary key?

A primary key must uniquely identify a record - i.e., each record can be expressed in the terms of "the record which has a key that equals X". Since null is not equal to any value, it cannot be used as a primary key.


Video Answer


1 Answers

Cassandra does not allow null clustering key values.

If you really need "no value" for some reason, then use an empty string OR some other special literal value like 'UNDEFINED' to cluster those together.

A similar question is here: How can I have null column value for a composite key column in CQL3

like image 167
icchanobot Avatar answered Sep 24 '22 23:09

icchanobot