How do you choose column types: money, INT(11), VARCHAR or TEXT?
Short answer
Money uses DECIMAL(p, s) + BigDecimal (or an integer in the smallest unit), never FLOAT/DOUBLE. INT(1) and INT(11) are identical; in PostgreSQL varchar(n) and text are stored the same way.
3 points to say:
- Money:
DECIMAL+BigDecimalorBIGINTminor units; buildBigDecimalfrom a string orvalueOf, never from adouble. INT(n): n is only display width, always 4 bytes; useBIGINTPKs from the start.- PostgreSQL:
varchar(n)is no faster thantext; MySQLTEXThas real limitations.
Keep reading the deep dive
Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.