MySQL field type for counting bytes

Morning

I store documents (Word, excel, ...) in a MySQL database. I have a “size” column where I store the file size in bytes, for example 582656, 136260, 383266 ... But when I order by size, the results are a little frustrated. What type of mysql field should I use? I tried VARCHAR and INT, the same result.

Regards, Emmanuel

+4
source share
1 answer

VARCHAR will definitely give you the wrong results, since the sort will sort from left to right.

for example, VARCHAR sorting will contain 12 to 2, since the first 1 of 12 is less than 2.

But INT should provide you with what you need.

Look at a few types here

Numeric types

+1
source

Source: https://habr.com/ru/post/1302117/


All Articles