Skip to content

About

Official code companion for the eBook "PostgreSQL: 1,000 Examples" — 52 Jupyter notebooks with all 1,000 runnable examples, seeded datasets, and the exact PostgreSQL 16 reference environment the book was verified against.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

PostgreSQL: 1,000 Examples — Companion

The practice environment for PostgreSQL: 1,000 Examples by Bi Learner.

Practice image Image size Build License


Start practising in one command

You need Docker Desktop, which is free for personal use, and nothing else.

docker run -d --name pg1000-practice \
  -p 8888:8888 -p 5432:5432 \
  bilearner/postgres1000-practice:1.1

Then open http://localhost:8888/lab.

PostgreSQL 16.15 is already running with the book's datasets loaded and all 53 chapter folders waiting. There is nothing to generate, nothing to load, and nothing to configure. First start is a few seconds.

The same image is on GitHub's registry too, if you prefer it or if Docker Hub's anonymous pull limit gets in your way on a shared network:

docker run -d --name pg1000-practice \
  -p 8888:8888 -p 5432:5432 \
  ghcr.io/bitoollearner/postgres1000-practice:1.1

To connect your own client instead — pgAdmin, DBeaver, DataGrip, PyCharm:

Setting Value
Host localhost
Port 5432
Database pg1000
Username book
Password book

What this repository is

The book is 1000 worked PostgreSQL examples across 53 chapters. Every one was executed against PostgreSQL 16.15 and its output captured — the printed row counts, sums and execution plans are real, not illustrative.

This repository is the environment those examples run in, so you can work through them on your own machine and get the same answers the book prints.

What you get here

  • The practice image — PostgreSQL 16.15, configured exactly as the book was verified against, with the datasets preloaded and JupyterLab on top.
  • 53 chapter notebooks — every example as a problem to solve, with an empty cell under it waiting for your SQL.
  • The datasets — the seeded generators, so the figures are reproducible rather than approximate.
  • The exact server configuration — conf/postgresql.conf, copied from the book's own build. Plans depend on these settings; a different work_mem or default_statistics_target produces a different plan.
  • A chapter index — all 1000 example titles, so you can find the one you need.

What is in the book, not here

The solutions, explanations, common mistakes, recommendations and pattern insights. Each example in the book carries all of them in a fixed seven-section format, plus a captured execution plan for the advanced tier.

That is the deal: the environment and the problems are free and open, and the answers are what you buy. The notebooks here give you the question and a blank cell — work it out, then check yourself against the book.

Get the book on Amazon Kindle


The datasets

Three schemas, each from a seeded generator, so your numbers match the printed ones exactly.

Schema Scale In the image? Used by
ecommerce 5,000 orders, 14,998 lines preloaded most of the book
hr 1,200 employees preloaded Chapter 49
ecommerce_lg 2,000,000 orders, 6M lines load on demand Part VIII

ecommerce_lg is not baked in because it would add roughly 850 MB to the image for the one part that needs it. Load it when you reach Part VIII:

docker exec -it pg1000-practice load-large-dataset

Index selection, partition pruning and BRIN cannot be demonstrated on five thousand rows — at that size the planner correctly prefers a sequential scan and every lesson inverts. See docs/DATASETS.md, including the defects the data contains on purpose.


Contents

conf/            the server configuration the book was verified against
datasets/        seeded generators and DDL for all three schemas
docs/            setup, datasets, troubleshooting, and the chapter index
notebooks/       53 chapter notebooks -- problems, not answers
practice-image/  the Dockerfile and entrypoint for the image above
scripts/         environment verification and dataset loading

Chapters

Part I — Getting Started

Part II — Data Definition and Types

Part III — Querying

Part IV — Composition and Analytics

Part V — Data Modeling

Part VI — PostgreSQL's Distinctive Types

Part VII — Objects, Transactions and Programming

Part VIII — Performance

Part IX — Data Engineering

Part X — Production Operations

Part XI — Capstone Projects


Difficulty mix

Level Examples What it means
Beginner 142 establishes a mechanism; usually one reasonable way to write it
Intermediate 729 applying it correctly, which is where most real difficulty lives
Advanced 129 carries a captured EXPLAIN plan and a performance discussion

Running without Docker

You can use any PostgreSQL 13 or later, but the book assumes the container's configuration and some output will differ. See docs/SETUP.md. The settings that matter are in conf/postgresql.conf, and the cluster locale must be C — text sort order depends on it, and every example that orders mixed-case text will differ otherwise.


Errata and questions

Found a mistake in the book, or an example that does not reproduce? Open an issue. Errata reports are especially welcome and are credited in the next revision.


Licence

The code, notebooks, configuration and dataset generators in this repository are MIT licensed — see LICENSE.

The book's text, example solutions and explanations are © Bi Learner and are not covered by that licence.

About

Official code companion for the eBook "PostgreSQL: 1,000 Examples" — 52 Jupyter notebooks with all 1,000 runnable examples, seeded datasets, and the exact PostgreSQL 16 reference environment the book was verified against.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages