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

A small collection from the MFA (the Museum of Fine Arts, Boston) in PostgreSQL 16: artists, their collections with creation dates and private notes, a permanent view and a read-only role. You write each statement in reps/NN/answer.sql, run the file with psql, and compare with the expected result printed in the statement.

You work in a copy of the set's starter, a repository of your own. Setting up the database is its first task: bring up a Postgres, load seed/ into it, and check what its README says you should find. How you run Postgres is your call.

Finish sql-designing-and-writing first; you should be able to read a join, an aggregate and a trigger. This set is about reading views: the rows one leaves out, and what a role can reach through one without reading the table behind it.

There are five collections by three artists, and one of them is soft-deleted. The permanent view collection_analysis shows only the titles and artists of active collections, and the role mfa_reader may read that view and nothing else. The soft-deleted row is there on purpose: a view that forgets to filter it out reports a collection the application meant to hide.

sql-optimizing comes after this set.

Reps

Do them in order. Each rep assumes the ones before it.

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