2

I'm inserting some data into a Cassandra table(/column family), and I need to generate a unique key. I've decided to use timeuuid for this, as it gives me nice sortability as well as uniqueness. I can use the now() function to generate the timeuuid, as in this CQL code:

insert into uuidtest ( something, else ) values ( now(), 'hola' );

The problem with this technique is that I have no idea what value I just inserted. I need to know this, as I'm going to need to use it later.

How can I retrieve this value at the time that I insert it (as I certainly can't guarantee that nobody else will insert one immediately after me)?

Brad Schoening
  • 1,281
  • 6
  • 22
Mark
  • 11,257
  • 11
  • 61
  • 97

1 Answers1

1

What Cassandra client are you planing to use? I don't think its possible to do this using plain cqlsh. But using a client API would allow you to create a timeuuid value separately and provide it as part of your insert statement along with the other values.

Stefan Podkowinski
  • 5,206
  • 1
  • 20
  • 25
  • Good answer...I was thinking pretty much the same thing. Although, if the OP wants to sort by the timeuuid, then using it as a partiton key won't do him a whole lot of good. – Aaron Mar 26 '15 at 21:35
  • I'm using the Datastax .NET client. The problem with generating them client-side is you have no guarantee of uniqueness. – Mark Mar 27 '15 at 17:29