Skip to content

Add lesson 19: CTEs#57

Merged
exekias merged 2 commits into
mainfrom
lesson/19-cte
Jun 11, 2026
Merged

Add lesson 19: CTEs#57
exekias merged 2 commits into
mainfrom
lesson/19-cte

Conversation

@exekias

@exekias exekias commented Jun 11, 2026

Copy link
Copy Markdown
Member

Adds the second lesson of the new Module 5: Intermediate querying — common table expressions (WITH, readability, chaining).

What's covered

  • The readability problem: a gnarly nested subquery rewritten with WITH — name your steps
  • Chaining multiple CTEs (filter → aggregate → join back)
  • Referencing one CTE more than once in the main query
  • A CTE works anywhere a table can appear (e.g. feeding an IN subquery)
  • Materialization in brief: Postgres 12+ inlines single-use CTEs; AS MATERIALIZED / AS NOT MATERIALIZED override
  • Pointers to data-modifying CTEs (WITH ... DELETE ... RETURNING) and the later recursive-CTE lesson

Seed

A tiny music-streaming dataset: artists, tracks, and plays (25 listens across June 2024), skewed so multi-step CTE chains produce meaningful results.

SELECT-only lesson, so per CONTRIBUTING.md it has no checks.

Note: this PR also bootstraps lessons/05-intermediate-querying/module.yaml, shared byte-for-byte with the sibling conditional-expressions and window-functions PRs so they merge cleanly.

Part of #6

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jun 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
learn-postgres Ready Ready Preview Jun 11, 2026 10:28am

The purge example in "Beyond SELECT" is now an exercise the learner
performs, verified by a row-count check on plays.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@exekias exekias merged commit 2a71fa7 into main Jun 11, 2026
3 checks passed
@exekias exekias deleted the lesson/19-cte branch June 11, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant