I read docs and can't figure out how to generate unique key using cloud-spanner. In SQL we have AUTOINCREMENT but it's anti-pattern in cloud-spanner. In docs UserId apear like: 001930, 001519, 011289, 010483, 000241 but didn't say how they generate these ids.
Cloud Spanner Key
1.5k views Asked by Sergiu At
2
There are 2 answers
0
On
To update the answer here, Cloud Spanner now supports auto incrementing. You can make use of GENERATE_UUID()
to accomplish auto incrementing and avoid hotspots.
You can read more in Google's blog post: Simplifying best practices at scale with auto-generated keys in Cloud Spanner
You have to generate your unique key values client side. There are no AUTOINCREMENT, SEQUENCE or other key generation options available server side in Cloud Spanner. You could do this client side with for example (the hash of) UUID's.