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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:40:15+00:00 2026-06-09T23:40:15+00:00

Using SQLite3, I am attempting to order my results by casting a TEXT string

  • 0

Using SQLite3, I am attempting to order my results by casting a TEXT string to INTEGER. Here is my query:

SELECT id,section FROM contract_sections ORDER BY CAST (section AS int)

The ‘section’ column is TEXT, and consists of a hierarchical/canonical identifier, i.e. 1.2.1, where each decimal reflects another level of depth within a hierarchy. I want my results returned in order (i.e. 1.2.8, 1.2.9, 1.2.10, etc). If I simply order by the ‘section’ column without a cast, i get a result that looks like:

1.1,
1.10,
1.2,
…

But with the aforementioned query with cast, it seems to be ordering correctly now, as in:

1.1,
1.2,
…
1.9,
1.10

My question is, if I cast this string to an int, what value is SQLite converting it to, and how will it be ordered as a result? It seems to be ordering things as I want at the moment, but want to avert any unforseen bugs.

  • 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-06-09T23:40:17+00:00Added an answer on June 9, 2026 at 11:40 pm

    Different databases handle casts to integers and floats differently.

    In the cast of SQL Lite, it converts the initial segment of the string that looks like an integer to an integer. So, cast(‘1.2.1’ as int) results in the integer 1.

    It behaves similarly for numerics, so cast(‘1.2.1’ as real) results in the value 1.2.

    This behavior is documented here (http://www.sqlite.org/lang_expr.html).

    Other databases might return an error in this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using sqlite3, if my query is SELECT * FROM table WHERE title LIKE '%x%'
I am switching from using SQLite3 to PostgreSQL, and hoped that I could populate
I have created a file named MyFile.db using SQLite3 from my C#.net application. This
I am using SQLite3. I load a table with say 30 rows using integer
How can I figure out the column names of a table using sqlite3 from
I am using SQLite3 for iPhone development and I'm attempting to wrap a few
I am using SQLite3 ODBC Driver as my connection string, Dim conn As ADODB.Connection
Using sqlite3, I have two tables: products, orders. I want to know how many
Using sqlite3, I have a table that looks like this: +---------+-----------------+----------+-----------+--------+ | ArtId |
I am using SQLite3 for development and PostgreSQL for deployment. However, I am facing

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.