backendgym backendgym — reps Sign in with GitHubSign in
← Reps
PostgreSQL Intermediate

SQL · Viewing

Read and judge views: aggregated, layered, partitioned, and the ones that hand a role exactly what it may see and nothing more.

sql-viewing / README.md

bgym start sql-viewing brings up a pinned Postgres 16 container with a small MFA collection. Nothing is installed on your machine. The base tables and seed data are in seed/; write each statement in reps/NN/answer.sql, and bgym run NN sends it to psql. bgym reset recreates the database and its roles.

You should have finished sql-designing-and-writing and be able to read a join, an aggregate and a trigger. This set is about what a view hides, what it keeps current, and who is allowed to see the table behind it.

There are five collections by three artists, one of them soft-deleted, with creation timestamps and a private note. The permanent analysis view exposes only active titles and artists. The imperfect row is deliberate: a view that forgets the deleted predicate reports a collection that the application meant to hide.

Do sql-designing-and-writing before this set. Do sql-optimizing after it.

Reps

In order — each one assumes the ones before it. Open a rep to read it.

  1. 01 01 · Expose current collections
  2. 02 02 · Aggregate through a view
  3. 03 03 · Judge a stale view
  4. 04 04 · Compare temporary and inline
  5. 05 05 · Soft-delete through a view
  6. 06 06 · Judge least privilege