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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:07:48+00:00 2026-05-14T02:07:48+00:00

I have an integer column and I want to find numbers that start with

  • 0

I have an integer column and I want to find numbers that start with specific digits.

For example they do match if I look for ‘123’:

1234567
123456
1234

They do not match:

23456
112345
0123445

Is the only way to handle the task by converting the Integers into Strings before doing string comparison?

Also I am using Postgre regexp_replace(text, pattern, replacement) on numbers which is very slow and inefficient way doing it.

The case is that I have large amount of data to handle this way and I am looking for the most economical way doing this.

PS. I am not looking a way how to cast integer into string.

  • 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-14T02:07:48+00:00Added an answer on May 14, 2026 at 2:07 am

    As a standard principle (IMHO), a database design should use a number type if and only if the field is:

    1. A number you could sensibly perform maths on
    2. A reference code within the database – keys etc

    If it’s a number in some other context – phone numbers, IP addresses etc – store it as text.

    This sounds to me like your ‘123’ is conceptually a string that just happens to only contain numbers, so if possible I’d suggest altering the design so it’s stored as such.

    Otherwise, I can’t see a sensible way to do the comparison using it as numbers, so you’ll need to convert it to strings on the fly with something like

    SELECT * FROM Table WHERE CheckVar LIKE '''' + to_char(<num>,'999') + '%'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an integer that I need to convert to a string
I have a table similar to this: CREATE TABLE example ( id integer primary
Say I have the classic 4-byte signed integer, and I want something like print
We have a file that has a 64 bit integer as a string in
I have a calc function in java script that takes three integer parameters, following
We have some integer arithmetic which for historical reasons has to work the same
I have an integer field in a ClientDataSet and I need to compare to
I have an NSAttributedString s and an integer i and I'd like a function
I have the following rails migration: create_table :articles do |t| t.integer :user_id, :allow_null =>
I have a stored procedure with the following header: FUNCTION SaveShipment (p_user_id IN INTEGER,

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.