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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:47:59+00:00 2026-05-31T00:47:59+00:00

I’ve got an SQLite database that will need to contain products. Those products have

  • 0

I’ve got an SQLite database that will need to contain products. Those products have a fixed-format composite product number, consisting of category, group and product number (cccccc.gg.ppp). Every time a new product is inserted, the new product number should be built using the category and group numbers, followed by the highest product number in that group incremented with one.

To that end, I was thinking of storing all three numbers in separate fields, and use a view to dynamically assemble the product number. For that to work, I would need to add leading zeroes, since the product number’s format is fixed.

However, I can’t seem to find a built-in SQLite function which would let me do this… 🙁

I’d rather not write a custom function, since we might have to share the database with other developers, for them to read data from; and I have no idea what platform or language they’re going to use.

Can this be done? Or will we have to find a different solution?

  • 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-31T00:48:01+00:00Added an answer on May 31, 2026 at 12:48 am

    This can be accomplished with a little bit of magic using string concatenation and the substr function. Long story short, here’s what you want:

    select substr('0000000000'||'1234', -10, 10)
    

    An explanation follows.

    First, know that SQLite’s string concatenation operator is ||.

    We’ll start by taking a string that is as long as the value we want to return. For example, if you want to return a number that is always 10 characters long and have it be left padded with 0s if it is shorter, then start with a string of ten 0s. To that, we will concatenate the number you want to return. In our example, that is ‘1234’. So far, we have the part that looks like this: '0000000000'||'1234'

    Then, pass that whole thing into the substr function. According to the documentation, here’s how the substr function works:

    The substr(X,Y,Z) function returns a substring of input string X that begins with the Y-th character and which is Z characters long. … If Y is negative then the first character of the substring is found by counting from the right rather than the left.

    So if you want the string to be 10 characters long, pass -10 as the Y parameter (to start counting from the right, 10 characters back) and pass 10 as the Z parameter (to take 10 characters total).

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

Sidebar

Related Questions

I have a pre-baked sqlite database that I want to use in my Android
I have an iOS app that stores some data in a sqlite database. The
I've got a C++ program that uses SQLite. I want to store the SQL
I have a SQlite database file with records which comes with my app. I
I have a last probleme before finishing my application. I use SQLITE DataBase. Everything
I've got a SQLite database. I'd like to create a field and declare it
So I've got a large database that I can't hold in memory at once.
I have an issue that has got me pretty stumped, and would appreciate some
I've got an android app using a local sqlite database. private SQLiteDatabase mDb; when
I'm using a SQLite database to store cover images of books I have in

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.