Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL field type to count bytes filesize

I'm storing document information (Word, excel, ...) in a MySQL database. I have a column "size" where I store the filesize in bytes like 582656, 136260, 383266... But when I order by size, the results are a little bit disorderly. What type of MySQL field should I use? I've tried VARCHAR and INT, the same result.

like image 445
maiis Avatar asked Nov 05 '22 16:11

maiis


1 Answers

VARCHAR will definitely give you the incorrect results as is will sort from left to right.

eg, VARCHAR sorted will place 12 before 2, as the first 1 in 12 is less than 2.

But INT should give you what you require.

Have a look at a couple of types here

Numeric Types

like image 51
Adriaan Stander Avatar answered Nov 12 '22 17:11

Adriaan Stander