Closed danielmewes closed 9 years ago
Sorting order of objects is another non-obvious one (I don't know how they sort actually. @mlucy?)
The data types document might be a good place to document this.
@danielmewes -- obj1 <=> obj2 == obj1.coerce_to('array') <=> obj2.coerce_to('array')
. We order the fields lexicographically and compare one by one, considering the absence of a key to be smaller than any value for a key.
So this explains how arrays elements are sorted and how object fields are sorted, but the other question is how types sort relative to one another -- if I have a sequence of [100, 200, "a", "b", [1, 2, 3], {"foo": "bar", "count": 999}, null], what happens?
Values of different types sort in the same order as their type names. (So if x
and y
are different types, x <=> y == x.type_of() <=> y.type_of()
.)
We've had many questions about how different ReQL types sort relative to each other, and also within one type.
For example it's not necessarily obvious that arrays sort lexicographically, and that
null
sorts between some other types (and not for example lower than all other types).We should explain this somewhere.