Skip to content

Document sorting order of ReQL types #734

Closed

Description

@danielmewes

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.

Activity

  1. danielmewes commented on Apr 24, 2015

    @danielmewes
    MemberAuthor

    Sorting order of objects is another non-obvious one (I don't know how they sort actually. @mlucy?)

  2. mglukhovsky commented on Apr 24, 2015

    @mglukhovsky
    Member

    The data types document might be a good place to document this.

  3. mlucy commented on Apr 24, 2015

    @mlucy
    Member

    @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.

  4. chipotle commented on May 5, 2015

    @chipotle
    Contributor

    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?

  5. mlucy commented on May 5, 2015

    @mlucy
    Member

    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().)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions