Search code examples
c++sql-serverboostsql-order-byuuid

How is ordering defined for UUIDs?


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?


Solution

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