Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 725507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:20:42+00:00 2026-05-14T06:20:42+00:00

Using Django 1.1, I am trying to select the maximum value from a varchar

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:20:42+00:00Added an answer on May 14, 2026 at 6:20 am

    In the spirit of “any help would be much appreciated”, you should figure out why it stopped working inside Django (but apparently not inside MySQL) – at 10,000.

    What is the query that is being generated? See this question for how to find that out.

    I suspect it is because you’re adding the +0 to make the sort numeric in your query. I don’t think Django supports this naturally, so you have two options:

    • People will undoubtedly want to know why you’re storing a number and asking for the maximum of it in a VARCHAR column. You could change the column to a numeric data type.
    • You could do what you have to do whenever you want to make some custom SQL call and Django doesn’t yet support it: write your own raw SQL.
    • Edit: You could also patch Django, but this might be a MySQL specific thing, so option #2 is probably your best bet.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to develop an app using Django 1.1 on Webfaction. I'd like to
I'm trying to design a bulk data import task using Django's ORM ontop of
I am trying to render the dictionary content using Django template like this for
I am trying to connect to a remote mysql database using django. The documentation
I'm trying to store Django data on MS SQL Server 2005 using: http://code.google.com/p/django-pyodbc/ (pyodbc
I am trying to upload an image using django and following a tutorial from
I am using Django 1.3 and trying to use .exists() on a model entry
I am trying to implement a to-do-list website to practice using Django. In models.py,
I'm trying to store the user's ID in the session using django.contrib.auth.login . But
I'm trying to set up OpenID authentication in Django, using django-authopenid. The instructions are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.