Sikau

PostgreSQL · Day 1 · about 25 min

Why PostgreSQL?

The database that does (almost) everything.

Beyond plain SQL

PostgreSQL is the most loved database among developers: open source, rock solid, standards-compliant — and packed with extras like JSON documents, arrays, full-text search, window functions, custom functions and row-level security. Many teams use it for *everything* instead of adding more databases.

Modern table definitions

SELECT version();

CREATE TABLE products (
  id int GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  name text NOT NULL,
  price_paisa int NOT NULL CHECK (price_paisa > 0),
  price_rupees numeric GENERATED ALWAYS AS (price_paisa / 100.0) STORED,
  created_at timestamptz NOT NULL DEFAULT now()
);

INSERT INTO products (name, price_paisa) VALUES ('Momo', 18000), ('Tea', 5000)
RETURNING id, name, price_rupees;
  • On your computer you'd use psql: \l lists databases, \dt lists tables, \d products describes one.
  • Hosted PostgreSQL: Neon, Supabase, AWS RDS, Google Cloud SQL, Render, Railway…
  • Everything from the Databases course works here — this course adds PostgreSQL's superpowers.

The rest of this lesson

  • Generated columnsexplain
  • Working in psqlexplain
  • Can you set it?predict
  • Writing a generated columnpredict
  • Your turnwrite code
  • Badge quizquiz
  • What you learnedrecap

Continue this lesson free — run real code in your browser

Continue with Google

See all 16 lessons of PostgreSQL