4

What is the maximum auto generated id in Google App Engine datastore?

Why this question?

I would like to show a more user-friendy id to my customer in a format like ####-####-#### using the alphabet:

 0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ

the character O has been removed to avoid confusion with the digit 0.

I need to know how many groups of ### are needed to represent all the ids.

Tony Baguette
  • 617
  • 7
  • 14
  • Alternatively, you can allocate a range of numeric IDs https://developers.google.com/appengine/docs/python/ndb/entities#numeric_keys – Gianni Di Noia Jul 27 '13 at 17:39
  • see **_MAX_LONG** for numeric IDs and **_MAX_KEYPART_BYTES** for string IDs here: https://github.com/GoogleCloudPlatform/datastore-ndb-python/blob/master/ndb/key.py – Nicholas Franceschina Aug 03 '16 at 19:50

2 Answers2

8

2^53 (the integer portion of a 64-bit float)

Alfred Fuller
  • 773
  • 3
  • 5
3

From the document "How Entities and Indexes are stored" (https://developers.google.com/appengine/articles/storage_breakdown/):

The first component of a key is the entity kind – the model or class name given to a model object (str). The next component is an ID (int64) or key name (str). Note that entities can have a numerical ID or key name but not both

So it sounds like the ID, if an integer is 64 bit, and I believe it is signed, so you would have 2^63 - 1 as the maximum value (9223372036854775807).

and from this part of the datastore (python) documentation: https://developers.google.com/appengine/docs/python/datastore/entities#Python_Assigning_identifiers

The Datastore can be configured to generate auto IDs using two different auto id policies:

The default policy generates a random sequence of IDs that are approximately uniformly distributed. Each ID can be up to 16 digits long.

The legacy policy creates a sequence of non-consecutive smaller integer IDs.

This would be 16 decimal digits (and hence 16 characters in length)

Troy Morehouse
  • 5,320
  • 1
  • 27
  • 38