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 7086931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:36:40+00:00 2026-05-28T07:36:40+00:00

I have a table with a name (varchar) field that only holds numeric string

  • 0

I have a table with a name (varchar) field that only holds numeric string and I want to order my queries by this field. But name fields are being ordered by alphabetically but I want them to be ordered numerically.
For instance if I get 1 2 200 100 as name fields values, It is being ordered like 1 100 2 200
but I need them to be 1 2 100 200.

I could be able to come up with following row query

select *
from my_table as t
where t.foo='bar'
order by cast(t.name as integer);

But cannot represent this as django orm querysets? is there any way to do that?

  • 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-28T07:36:41+00:00Added an answer on May 28, 2026 at 7:36 am

    I’d ask first of all why you have a varchar column that needs to be treated as numeric, but never mind.

    You can use the extra queryset method to convert your string:

    MyTable.objects.extra(select={'int_name': 'CAST(t.name AS INTEGER)'},
                          order_by=['int_name'])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table where a record looks like this varchar(255) Name varchar(255) Text
Suppose that i have a table 't' with fields 'id' int 11, 'name' varchar
I have a table with name varchar address varchar country varchar city varchar .....
I have a table named categories, which contains ID(long), Name(varchar(50)), parentID(long), and shownByDefault(boolean) columns.
I have these tables: customer -------- customer_id int name varchar(255) order ----- order_id int
So here's the setup. I have two tables: CREATE TABLE dbo.TmpFeesToRules1(Name varchar, LookupId int)
I have a database table that looks like this: CREATE TABLE IF NOT EXISTS
I have a typical table, e.g. id(int) name(varchar) address(varchar) date(datetime) I also have a
I have a table structure like the following: table a: id int name varchar
We have two tables. The first contains a name (varchar) field. The second contains

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.