Cloud Spanner Key

1.5k views Asked by At

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.

2

There are 2 answers

10
Knut Olav Løite On BEST ANSWER

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.

0
adam2k 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