google-cloud-platformgoogle-cloud-spanner

Cloud Spanner Key


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.


Solution

  • 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.