S
S
suhuxa12017-07-16 10:01:30
MySQL
suhuxa1, 2017-07-16 10:01:30

Why can't varchar be used for numbers?

Greetings!
A lot of numbers have to be entered into a table of the form: 0.0000000002324, 23.465099892348 and the like. There are no plans to sort by numbers or anything like that. Just store them in the database and display them in this form in the right places. The question arose, is it possible not to use double when designing a database, but, for example, varchar 60 ? 60 characters is enough. What are the disadvantages of this case? I clearly understand that in this case the number will be stored as a string, but operations with numbers will not be required. And if it is required, then it will be possible to solve it through parseInt, for example.

Answer the question

In order to leave comments, you need to log in

6 answer(s)
A
Alexander Aksentiev, 2017-07-16
@Sanasol

sanasol.ws/2015/09/16/little-big-mysql-query-story
History (more precisely, even a screenshot) about how once I accidentally made varchar instead of integer
But of course I mixed it up in that place there should have been a primary key, or rather a link on him.
Therefore, such sadness.
If where is not planned for this column, then of course this will not happen.
But in general, the story is about using the correct types for the data.
Although, again, now I myself store numbers in the database as varchar because they are sooooo long. More max interger

V
Valery Khizhevsky, 2017-07-16
@Roshette

Cons in loading resources, and access time, to information

S
Sumor, 2017-07-16
@Sumor

When computers were big...
In general, to write large numbers in digits, with the ability to work with each digit, the packed decimal or binary-coded decimal type was invented. Its support is still in modern processors. The point is that the number 0-9 is stored in every 4 bits of the number, the AF values ​​\u200b\u200bare not used. Gain in storage, in comparison with varchar - in 2 times.
You can expand on this theme and store numbers in an Int32 array using numbers from 0-999999999 with 9 digits in each element. To translate into a string, it is enough to translate each number into a string and connect.

K
Konstantin Tsvetkov, 2017-07-16
@tsklab

Can.

Just store them in the database and display them in this form in the right places.
Client localization may be different.
Alignment will be difficult.

A
Arris, 2017-07-16
@Arris

How about DECIMAL ? Anything will be better than varchar.

D
d-stream, 2017-07-16
@d-stream

What is the point of screwing triangular bearings with bells to a bicycle with square wheels?
You need to start from the source - what are the requirements for the values. The phrase "I only store" can generally provoke to "not store." Or else there will be at least some use.
And in the normal version - decimal, or real, but with a clear understanding of what real is good and what is bad.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question