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

 

question

amitmund_177224 avatar image
amitmund_177224 asked ·

Why use CQL function UUID() over NOW() ?

why we should use uuid() over now() in anyway? Best to my current understanding now() is anyway much better then uuid()

EDIT: Sorry, seems I could not explain the question. Let me try again. While going through the DS201, of topic UUID and TIMEUUID and as per the example, both the output looks the similar ( length of chatters: 8-4-4-4-12 ) and as per the video, its says => TIMEUUID embeds a TIMESTAMP value and we can generate UUID with uuid() function and TIMEUUID with now() function and we can do sort over TIMEUUID

So, I am trying to understand, what is the benefit of using UUID over TIMEUUID, where to best of my current understanding as per the video, TIMEUUID is the superset of UUID. TIMEUUID have everything over UUID, then on what scenario someone should use UUID over TIMEUUID and on what scenario TIMEUUID is bad choice over UUID.

performance
10 |1000 characters needed characters left characters exceeded

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

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered ·

@amitmund_177224 unless I misunderstood your question, those functions are 2 different things. UUID() generates a random type 4 UUID (keyword is random). NOW() generates a type 1 encoded time UUID of the current time.

You would use one over the other depending on your use case. Cheers!

4 comments Share
10 |1000 characters needed characters left characters exceeded

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

EDIT: Follow-up added to original question since it was not an "answer".

0 Likes 0 · ·

@amitmund_177224 still makes no difference. You would pick a time UUID because your use case has a time component to it. Just using a UUID will give you a universally unique random ID. It all depends on what you need/want out of the data type. Cheers!

0 Likes 0 · ·

Thank you for the guide. Just want to correct my understanding, so there is no issue using TIMEUUID by default, as I believe, it generate uniq as well as we can short, if needed.

0 Likes 0 · ·

@amitmund_177224 by definition, UUIDs are universally unique. The difference is that one is a random type 4 ID while the other is time-based. Since time UUIDs are timestamps, you can sort them in chronological order. Cheers!

0 Likes 0 · ·