← Back to PostgreSQL Course | Chapter 1: Introduction | Lesson 7 of 7

Data types overview

PostgreSQL offers many column types, and choosing the right one saves space and prevents mistakes.

In this page:

  1. Data types overview
Syntax
sql
column_name integer
column_name numeric(precision, scale)
column_name text
column_name boolean
column_name timestamp

Data types overview

Common types are integer types (smallint, integer, bigint), numeric(p,s), real and double precision, text and varchar(n), boolean, date, time, timestamp and timestamptz, uuid, json and jsonb, arrays and bytea.

PostgreSQL also supports enums, ranges and custom types. Pick the narrowest type that fits and use numeric for money.

Note: Prefer timestamptz for moments in time and numeric for currency.

Example: Data types overview

bash
shop=# CREATE TABLE sample (
shop(#   id        bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
shop(#   qty       integer,
shop(#   price     numeric(10,2),
shop(#   title     text,
shop(#   active    boolean,
shop(#   created   timestamptz DEFAULT now(),
shop(#   attrs     jsonb,
shop(#   tags      text[]
shop(# );
CREATE TABLE

⚠️ Run this in your own terminal or Node.js environment.

Related Topics
Common Mistakes
  1. Using float for money
  2. Storing dates as text
  3. Using varchar(255) everywhere without a reason
Chapter Summary
  • Integers: smallint, integer, bigint
  • Text: text and varchar(n)
  • Time: date, timestamp, timestamptz
  • Also boolean, numeric, uuid, jsonb, arrays
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.