It works if you have just 0-9A-Z in tree_encodings (deci 0..35). This will tend to make your tree_sortkeys longer of course.
If we keep it as is, a dependency check would be a good idea. A simple select 'a' < 'A' might do the trick.