SteelReed

Search

Search posts, questions…

Junior

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.

moneyprimary keyintegerstring, PostgreSQLWhat does the columnhold?DECIMAL + BigDecimalor BIGINT minor unitsBIGINT from day oneINT: n in INT(n)is display width onlytext or varchar(n)same thing

3 points to say:

  1. Money: DECIMAL + BigDecimal or BIGINT minor units; build BigDecimal from a string or valueOf, never from a double.
  2. INT(n): n is only display width, always 4 bytes; use BIGINT PKs from the start.
  3. PostgreSQL: varchar(n) is no faster than text; MySQL TEXT has 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.