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

  • Home
  • SEARCH
  • 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 8300121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:25:52+00:00 2026-06-08T16:25:52+00:00

I have a database table with a primary key called PremiseID. Its MySQL column

  • 0

I have a database table with a primary key called PremiseID.

Its MySQL column definition is CHAR(10).

The data that goes into the column is always 10 digits, which is either a 9-digit number followed by a space, like ‘113091000 ‘ or a 9-digit number followed by a letter, like ‘113091000A’.

I’ve tried writing one of these values into a table in a test MySQL database table t1. It has three columns

mainid integer
parentid integer
premiseid char(10)

If I insert a row that has the following values: 1,1,'113091000 ' and try to read row back, the ‘113991000 ‘ value is truncated, so it reads ‘113091000’; that is the space is removed. If I insert a number like ‘113091000A’, that value is retained.

How can I get the CHAR(10) field retain the space character?

I have a programmatic way around this problem. It would be to take the len(‘113091000’), realize it’s nine characters, and then realize a length of 9 infers there is a space suffix for that number.

  • 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-08T16:25:53+00:00Added an answer on June 8, 2026 at 4:25 pm

    To quote from the MySQL reference:

    The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255. When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed.

    So there’s no way around it. If you’re using MySQL 5.0.3 or greater, then using VARCHAR is probably the best way to go (the overhead is only 1 extra byte):

    VARCHAR values are not padded when they are stored. Handling of trailing spaces is version-dependent. As of MySQL 5.0.3, trailing spaces are retained when values are stored and retrieved, in conformance with standard SQL. Before MySQL 5.0.3, trailing spaces are removed from values when they are stored into a VARCHAR column; this means that the spaces also are absent from retrieved values.

    If you’re using MySQL < 5.0.3, then I think you just have to check returned lengths, or use a character other than a space.

    Probably the most portable solution would be to just use CHAR and check the returned length.

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

Sidebar

Related Questions

I have a database table called users with a primary key of user_id for
I have a table called Picture in my database. I'm using the primary key
I have a database table A which stores records, A has a primary key
I'm creating a database table and I don't have a logical primary key assigned
In my database I have table AnimalDetails containing animalNumber(primary key),name,breed dateofbirth and an image
I have a database table called Genre with the following fields: Id (Seeded Primary
I have two database tables. One table stores data for a commitment that a
I need to get the last inserted id of table that have multi-column primary
I'm making a small DataBase with MySQL Workbench. I have a main table, called
I have a database table which has a compound primary key (id_a, id_b) .

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.