Course map
Stage 1: Foundation
Stage 2: Intermediate
Stage 3: Advanced
Stage 4: Performance & internals
Stage 5: Specialization

Part 03 / Topic 1 of 9

The core types

Every column has a type, and the type is a promise the database enforces: a price numeric(10,2) will never, ever hold the text cheap. The types you will actually use:

Type Holds Use for
integer whole numbers to ±2.1 billion counts, quantities, everyday ids
bigint whole numbers to ±9.2 quintillion ids in huge tables, event counters
numeric(p, s) exact decimals: p digits, s after the point money, anything that must be exact
text text of any length names, emails, descriptions — the default
varchar(n) text, errors beyond n characters only when a real length rule exists
boolean true / false (psql shows t / f) flags
date a calendar date birthdays, order dates
timestamptz an exact moment, time-zone aware "when did this happen"
timestamp wall-clock reading, no zone rare — see next section
interval a duration "3 days", "2 hours 30 minutes"
uuid a 128-bit unique identifier ids that must be globally unique

Types buy you three things: correct storage (numbers stored as numbers), correct behaviour (ORDER BY price sorts numerically, not alphabetically where '80' < '9'), and early errors (a bad value is rejected at write time, not discovered in a report six months later).

shopdb uses them all — look back at any \d output and you can now read every line of it.

🧪 Quick quiz — answer from memory, then check.

  1. A quantity column for order lines — which type?
  2. What does psql print for boolean true?
Show the answers
  1. integer — quantities are whole numbers well under 2.1 billion.
  2. t (and f for false).

Done here? The practice set for Part 3 — 7 exercises with solutions — is on the part page.

Search the guide