Skip to content

Instantly share code, notes, and snippets.

@mKaloer
Created November 9, 2016 07:37
Show Gist options
  • Save mKaloer/d20d827d37887a3fa8ff7bce5aa6299c to your computer and use it in GitHub Desktop.
Save mKaloer/d20d827d37887a3fa8ff7bce5aa6299c to your computer and use it in GitHub Desktop.
Python implementation of comparison algorithm for SQL Server GUID (uniqueidentifier)
def less_than_guid(a,b):
"""
This implements the weird comparison method for sql server
GUID.
"""
groups = [slice(10,16), slice(8,10), slice(6,8), slice(4,6), slice(0,4)]
for g in groups:
if a.bytes[g] < b.bytes[g]:
return True
elif a.bytes[g] > b.bytes[g]:
return False
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment