Goal: Identify three independent data protections, provoke their specific errors, and save a valid row with a timestamp default.
Before exploring constraints, connect to the correct database. Run psql -U beer_db -d beer_db to open a psql session as the beer_db user.
Inspect \d beers. Locate NOT NULL for name and ABV, CHECK for ABV 0 through 25, and the primary key. Then inspect \d breweries for the UNIQUE name constraint and \d beer_ratings for its score rule and timestamp default. Each upcoming insert targets a different rule.
Insert Too Strong with ABV 30.0, outside the allowed 0–25 range. The provided subquery selects one real brewery ID (ORDER BY id LIMIT 1 makes that choice repeatable), so the intended CHECK is the failing rule. Expect beers_abv_check; the rejected row is not saved.
Repeat with a valid ABV but omit name. The brewery-ID subquery provides a valid parent just as before. Expect a not-null violation naming name, rather than the ABV CHECK error. This separates a missing value from an out-of-range value.
First look up Golden Brewery and its city. Then insert the same name with city Brno. Expect breweries_name_key: uniqueness applies to the name, so a different city cannot make the duplicate valid.
Insert score 8.5 with a real beer ID and reviewer Test Reviewer. RETURNING shows score and whether the omitted timestamp was filled by its default. Expect 8.5, t, and INSERT 0 1: valid inputs are accepted by the same database that rejected the three bad inserts.