Skip to content
Learn Netverks

Lesson

Step 7/36 19% through track

data-types-postgresql

PostgreSQL data types

Last reviewed May 28, 2026 Content v20260528
Track mode
sql_sandbox
Means
SQL sandbox
Reading
~2 min
Level
beginner

This lesson

This lesson teaches PostgreSQL data types: the SQL patterns, schema habits, and query reasoning you need before advancing in PostgreSQL.

Teams query PostgreSQL data types on every PostgreSQL codebase—skipping it leaves gaps in debugging and data reviews.

You will apply PostgreSQL data types in contexts like: Modern startups, geospatial apps, and analytics-friendly OLTP systems.

Copy Postgres SQL into psql, local PostgreSQL, or DB Fiddle (PostgreSQL dialect)—use \d and EXPLAIN ANALYZE where lessons show them. The in-browser lab ships later; psql is the practice path now.

When you can explain the previous lesson's ideas without copying example queries verbatim.

Postgres offers rich scalar and structured types. Choosing the right type prevents bugs (timezone-less timestamps) and enables indexing (INET for IPs, JSONB for documents).

Common scalars

CREATE TABLE type_demo (
  id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  sku TEXT NOT NULL,
  price NUMERIC(10,2) NOT NULL,
  weight DOUBLE PRECISION,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
  active BOOLEAN NOT NULL DEFAULT true,
  ip INET
);

Practice: Run in psql or DB Fiddle (PostgreSQL). Use your practice database from the workflow lesson.

Text: TEXT vs VARCHAR

Both store strings; performance is similar in modern Postgres. Use TEXT unless you need a documented length cap for validation.

Time types

SELECT
  now() AS server_now,
  CURRENT_DATE AS today,
  '2026-05-28 10:00:00+00'::timestamptz AS explicit_utc;

Prefer TIMESTAMPTZ (timestamp with time zone) for application timestamps—stores UTC internally, displays in session timezone.

Important interview questions and answers

  1. Q: NUMERIC vs DOUBLE PRECISION for money?
    A: NUMERIC is exact decimal; floats can round—use NUMERIC for currency.
  2. Q: TIMESTAMP vs TIMESTAMPTZ?
    A: TIMESTAMPTZ stores absolute instants; plain TIMESTAMP ignores time zone and causes bugs across regions.

Self-check

  1. Which type should store currency amounts?
  2. Why avoid TIMESTAMP without time zone for user events?

Tip: Use TIMESTAMPTZ and NUMERIC for production timestamps and money—avoid float currency.

Interview prep

Money type?

NUMERIC( precision, scale ) for exact decimal currency.

TIMESTAMPTZ?

Stores absolute instants; displays in session timezone.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • TIMESTAMPTZ why?
  • BOOLEAN vs bool?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump