Skip to content

Dariush Abbasi · PostgreSQL 17

Postgres by Example

Fifty-seven short lessons take you from the first query through data modeling, querying, indexes, transactions, stored logic, search, and day-to-day operations.

Prerequisites

Get the SQL bundle and a practice database

The lessons target PostgreSQL 17 and the psql client. Later-version features are identified explicitly; the official documentation is a useful companion.

  1. Download the bundle

    Download the complete SQL bundle, extract it into a new directory, and run commands from the directory containing source/.

  2. Create a practice database

    The lessons create, change, and drop their demo tables, so use a disposable database and substitute it for postgres in the examples:

    createdb pbe
  3. Run the first lesson

    psql -X -v ON_ERROR_STOP=1 -f source/first-query.sql pbe

Reading order

Read in chapter order. Before chapter 6, create the sample table using the files introduced in chapters 16 and 24:

psql -X -v ON_ERROR_STOP=1 -f source/create-table.sql -f source/insert.sql pbe

Chapter 16 recreates the table; chapter 24 fills it again. Later join lessons depend on chapter 29, and the recursive example also uses chapter 31. When skipping ahead, follow the lesson’s prerequisites. Optional exercises can change later results. Dates, UUIDs, catalog listings, query plans, and timings vary; ellipses in console transcripts mark omitted output.

Two special cases

Chapter 46 deliberately raises a duplicate-key error: run it with ON_ERROR_STOP=off so the subsequent rollback and cleanup execute. For chapter 55, use a non-superuser database owner without BYPASSRLS; superusers bypass row security even with FORCE ROW LEVEL SECURITY.

Editions

English edition, Chinese translation, and SQL bundle

SQL bundle

examples.zip · every lesson’s SQL files

Postgres by Example by Dariush Abbasi is published in boringcollege/postgres-by-example under CC BY 4.0. This edition is based on commit ffde0d3; reviewed technical changes are listed in Editorial Corrections, and sources and licenses in Publication and License.