0

When strings are indexed in Datastore, what order are they indexed in?
Are number characters like "8" and "9" considered higher or lower than "a" or "b"?

For example, in ascending order, how would these strings appear?
"111", "112", "1111", "abc", "2ab", "aabb"

skaul05
  • 2,154
  • 3
  • 16
  • 26
Micro
  • 10,303
  • 14
  • 82
  • 120

1 Answers1

0

Strings in Datastore are Unicode strings. I tested this by creating 6 entities with a property named string as string. The result was:

SELECT * FROM EntityKind ORDER BY string ASC

111
1111
112
2ab
aabb
abc

Just like sorting in python an string:

a = ["abc","aabb","2ab","112","1111","111"]
a.sort()
print(a)

Will output:

['111', '1111', '112', '2ab', 'aabb', 'abc']
Nahuel Varela
  • 1,022
  • 7
  • 17
  • Interesting, so even though "abc" has less characters than "1111", it still comes after? So if the set was "z" and "1234567890" the order would be `['1234567890', 'z']`? Why is that? – Micro Feb 24 '19 at 21:29
  • @Micro I know it's a little late but because Google's Datastore sorts characters in ASCII-sort order, Where numbers come before letters, capital letters come before lowercase letters and special characters are all over the place. [ASCII-sort order chart](http://support.ecisolutions.com/doc-ddms/help/reportsmenu/ascii_sort_order_chart.htm) – Scott K. May 22 '21 at 01:07