You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
@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?
Activity
danielmewes commentedon Apr 24, 2015
Sorting order of objects is another non-obvious one (I don't know how they sort actually. @mlucy?)
mglukhovsky commentedon Apr 24, 2015
The data types document might be a good place to document this.
mlucy commentedon Apr 24, 2015
@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.chipotle commentedon May 5, 2015
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?
mlucy commentedon May 5, 2015
Values of different types sort in the same order as their type names. (So if
xandyare different types,x <=> y == x.type_of() <=> y.type_of().)