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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With