Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started



Tri avatar image
Tri asked smadhavan rolled back

Is there a CQL data type equivalent to Enum?

Is there an ENUM datatype in Cassandra? For example, using a pseudo-CQL language:

CREATE ENUM MovieGenre (Comedy, Romance, Fantasy, SciFi)

Then use it as:

INSERT INTO myMovie (movieid, name, genre)
VALUES (124-abcd, 'The Enum Story', MovieGenre.SciFi);

The idea is to use a more compact encoding of the values and avoid unintended creation of new values because of typos or case sensitivity.

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

smadhavan avatar image
smadhavan answered smadhavan rolled back

@Tri, CQL does not have an enum data type. It would have to be done from the application writing into the database. For example, one could write their own custom codec implementation using DataStax Java Driver 4.7 which was implemented as part of JAVA-846.

Alternatively, if you're looking for User Defined Type (UDT), refer to this documentation for working with them.

[EDIT] UDTs are not equivalent to enums.

I hope that helps!

4 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

@smadhavan Can you please show an example how to use UDT to fit a use-case of "Must-be-one-among-these" like enum?

BTW what is the syntax to write the inline code like the enum in red in your reply above? I used markdown (surround by backticks) but it seems not compatible in this board.

0 Likes 0 ·

@Tri, I had updated my response above to clarify that UDTs are not equivalent to enums.

For using markdown style responses, please refer to this post explaining how to set it in your community profile.

1 Like 1 ·

The DataStax Java Driver 4.7 you indicated is closer to what I was looking for. Thanks. Does that work with open source Cassandra? If yes, does it require a license?

0 Likes 0 ·
Show more comments