title: How can I compare version numbers in SQLAlchemy? (Given a function to do so)
body: <p>I have this function for comparing version numbers:</p>
  
  <pre><code>def version_gt(left, right):
      """
      Compare two version numbers telling which is greater    
  
      Returns True if left is greater, False if right is greater.
      """
      left = map(int, filter(None, str(left).split('.')))
      right = map(int, filter(None, str(right).split('.')))
      for i in range(max([len(left), len(right)])):
          if i &gt; len(left)-1:
              # left ran out of version numbers, therefore right is greater
              return False
          elif i &gt; len(right)-1:
              # right ran out of version numbers therefore left is greater
              return True
          else:
              # compare versions only if the version number is different
              if left[i] != right[i]:
                  return left[i] &gt; right[i]
      return False # if all is equal, return False since left is not greater
  </code></pre>
  
  <p>How can I use this in SQLAlchemy to compare version numbers in a select statement?</p>
  
  <p>I couldn't figure out the online documentation. Thanks for your help.
  -Sunjay03</p>
  
  <p>[EDIT] Here is how I have defined the columns:</p>
  
  <pre><code>Table("updates", metadata,
      Column("u_id", Integer, primary_key=True),
      Column("appname", String, nullable=False),
      Column("version", String, nullable=False),
      Column("uploaded", DateTime, default=func.now()),
  )
  </code></pre>
  
  <p>The answer has something to do with this:
  <a href="http://www.sqlalchemy.org/docs/orm/mapper_config.html#custom-comparators" rel="nofollow">http://www.sqlalchemy.org/docs/orm/mapper_config.html#custom-comparators</a></p>
  
  <p>I couldn't understand it very well, maybe you can.</p>