Pcornel
Databases · Schema, Keys & Data Types

Choosing Data Types

Cheat sheet · https://pcornel.dk/topic.php?topic=6168

Back to the Topic

Answer

Data types define what a column can hold: integers, numeric/decimal, text, dates/timestamps with or without time zone, booleans, UUIDs, JSON.

Remember

Money in DECIMAL/NUMERIC, not float. Timestamps with time zone (store UTC). Sizes that fit growth (bigint for IDs). Avoid storing numbers or dates as text.

First checks

  • \d <table> — first check for this topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -S <server> -Q "SELECT @@VERSION" — SQL Server reachable and version

Verify in this order

value → type validation → storage → comparison/sorting

Where it usually breaks

utf8 in older MySQL is limited to three bytes and cannot store emoji; use utf8mb4.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6168

Confirmation

Confirm action

Continue?