arshellium
arshellium

Reputation: 235

Cassandra: Can't use 'NOT NULL' constraint while creating table

I see many examples on here that create tables using the NOT NULL constraint. Ironically I can't seem to do the same.

This is the cql command I use :

CREATE TABLE activities_dev (activity_id  uuid ,actor_id bigint NOT NULL, actor_appid bigint NOT NULL, item_id text NOT NULL, verb text NOT NULL,viewer_id bigint NOT NULL,viewer_appid bigint NOT NULL, ts timestamp, PRIMARY KEY(activity_id,actor_id,actor_appid,item_id,verb));

but this is the error I get:

SyntaxException: line 1:62 mismatched input 'NOT' expecting ')' (...activities_dev(activity_id uuid, actor_id integer [NOT] NULL...)

What am I doing wrong ?

Upvotes: 5

Views: 12388

Answers (3)

ARA
ARA

Reputation: 1316

Null column in Cassandra does not mean empty column.

Cassandra uses nulls for marking deleted columns : you can delete one or several columns of a row in Cassandra.

This timestamped marker called tombstone is used for data reconciliation locally and between nodes (Commitlog, memtables, SStables) and in replicated keyspaces prevents resurrection of data (see this article for example about replicated deleted).

In this context, it makes sense not to allow a 'NOT NULL' clause in CREATE TABLE and ALTER TABLE CQL syntax.

Alain

Upvotes: 2

Ashraful Islam
Ashraful Islam

Reputation: 12840

In Cassandra NOT NULL keyword not supported.

For primary key columns cassandra automatically handle that. If you try to insert null to any primary key value cassandra will throw exception

Invalid null value in condition for column

Upvotes: 7

Palestine Hacker
Palestine Hacker

Reputation: 11

First of all if your modifying this Column to be as NOT NULL , check that all fields inside this column to have value.

Upvotes: 0

Related Questions