django select max field from mysql when column is varchar

Posted by doza on Stack Overflow See other posts from Stack Overflow or by doza
Published on 2010-04-17T23:33:28Z Indexed on 2010/04/17 23:53 UTC
Read the original article Hit count: 670

Filed under:
|
|
|
|

Hi,

Using Django 1.1, I am trying to select the maximum value from a varchar column (in MySQL.) The data stored in the column looks like:

9001
9002
9017
9624
10104
11823

(In reality, the numbers are much bigger than this.)

This worked until the numbers incremented above 10000:

Feedback.objects.filter(est__pk=est_id).aggregate(sid=Max('sid'))

Now, that same line would return 9624 instead of 11823.

I'm able to run a query directly in the DB that gives me what I need, but I can't figure out the best way to do this in Django. The query would be:

select max(sid+0) from Feedback;

Any help would be much appreciated.

Thanks!

© Stack Overflow or respective owner

Related posts about django

Related posts about python