2

I am stuck in the following problem. I have two UUIDs

const boost::uuids::uuid first = Helper::String2UUID("43E3F007-3993-4587-801E-D24C012587E4"));
const boost::uuids::uuid second = Helper::String2UUID("652335C1-6479-4D6A-9599-25A671366E05"));

In Boost I am getting this to be true.

BOOST_REQUIRE(first < second);

But when I do query on SQL Server using ordering for that UUID column it turned out that

second < first

Looks like ordering for UUIDs is different from one application to another. Does it mean that there is no general rule for ordering UUIDs or am I doing something wrong?

Dale K
  • 25,246
  • 15
  • 42
  • 71
Ashot
  • 10,807
  • 14
  • 66
  • 117
  • 3
    The SQL Server approach is discussed here https://stackoverflow.com/questions/7810602/sql-server-guid-sort-algorithm-why – Martin Smith May 03 '20 at 22:50
  • 1
    See [How many ways are there to sort GUIDs? How much time do you have?](https://devblogs.microsoft.com/oldnewthing/20190426-00/?p=102450) and [Another way to sort GUIDs: Java](https://devblogs.microsoft.com/oldnewthing/20190913-00/?p=102859). A GUID/UUID is just an array of binary numbers, how they are sorted is implementation-defined, yes. – Remy Lebeau May 04 '20 at 07:57

1 Answers1

1

There is no official ordering UUIDs since they are just an opaque string of 128 bits with no inherent meaning. Some applications may "helpfully" define them to be ordered, but since there is no official ordering to follow, they may make different decisions on how to do that. It may even vary between instances of the same application, e.g. due to endianness of the machine they're running on.

StephenS
  • 1,813
  • 13
  • 19