SQL

CivicGrid's data lives in Postgres, and most of my data rules are really SQL rules: write by a stable key, dry-run first, keep a backup, check the invariants afterwards.

SQL with Postgres

Hands-on with Postgres in a Docker container, on a made-up Larkspur County database of towns, leaders and meetings. Each lesson explains one idea, has you try it on data whose right answers are known, then shows how CivicGrid uses it, including where it went wrong.

  1. 1What a database is, and why SQLComing soon
  2. 2Your first database: Postgres and psqlComing soon
  3. 3Asking questions: SELECT, WHERE and ORDER BYComing soon
  4. 4Counting and groupingComing soon
  5. 5Joining tablesComing soon
  6. 6Designing tables: keys, types and constraintsComing soon
  7. 7Changing data safelyComing soon
  8. 8NULL, and the other trapsComing soon
  9. 9Indexes, and reading EXPLAINComing soon
  10. 10Checks as queriesComing soon
  11. 11Who can see what: roles and row-level securityComing soon
  12. 12SQL from code, and SQL injectionComing soon
  13. 13Backups, and restoring themComing soon

PostgreSQL documentation (opens in a new tab)

The official manual. The tutorial chapter is a good first read.

Free

SQLBolt (opens in a new tab)

Short interactive lessons that run in the browser.

Free

PostgreSQL Exercises (opens in a new tab)

Practice questions on one sample database, from simple to hard.

Free