Reputation: 441
I know that cqlsh has uuid() function I can use doing INSERT using cqlsh. But I want to do INSERTs (or creating data from app with driver) without generating uuid on client side.
Upvotes: 0
Views: 660
Reputation: 16420
You can use uuid() in your queries outside of cqlsh which would generate them on the coordinator. You dont need to specify them, ie:
session.execute("INSERT INTO blah (id, value) VALUES (now(), 'bob')");
# id being a timeuuid type, or can use uuid() for a random
That said it can actually be better to do them on client side. If you do them client side your inserts are idempotent. If you have the function providing the key to be generated on coordinator you cannot retry it on a different coordinator if there are write timeouts. Write timeouts may or may not have been applied so its better if you can just retry.
Theres no concern of collisions by the way. Particularly if you use type 1 uuid's, its impossible for them to collide. Even with >10,000 a millisecond a host (which is the precision of timeuuids, since its number of 100 nanoseconds since creation of Gregorian calendar), most libraries are monotonically increasing and will just progress into future milliseconds ensuring you will never have duplicates.
Upvotes: 3