Goal: Inspect real type choices, create your own table, and observe defaults and decimal scale on a saved row.
Connect to beer_db as its ordinary owner role beer_db, which can create and modify objects here without superuser privileges. Expect beer_db=>.
Inspect \d breweries. Find the UUID primary key and its gen_random_uuid() default, text name/city, nullable integer year, and timestamp with time zone creation time. A default supplies omitted input; NOT NULL rejects missing values without a default.
Inspect both beers and beer_ratings. Find ABV numeric(4,2) and score numeric(3,1). Precision is the total number of decimal digits; scale is digits after the decimal point. These types round to their declared scale and reject values outside their range.
Insert Test Brewery with only name and city. RETURNING reports the saved row. Omit id so its default generates a UUID; test id IS NOT NULL as a boolean so the observation is stable across resets. Expect Test Brewery, Prague, t, and INSERT 0 1 (zero is the legacy OID field; one is the inserted row count).
Compare the same addition using float8 and numeric. :: casts each decimal literal to the chosen type. Expect 0.30000000000000004 versus 0.3. Binary floating point approximates these inputs; numeric represents these decimal fractions exactly. This does not mean every decimal, such as 3.5, is inexact in float8.
Create the separately named type_demo table, leaving the course tables intact. Use an automatically generated UUID primary key, text label, integer quantity, numeric(5,2) price, and timestamptz creation time. PRIMARY KEY adds uniqueness and NOT NULL. Expect CREATE TABLE, then inspect all five columns with \d type_demo.
Insert label Sample, quantity 2, and price 12.345. Omit the UUID and timestamp so defaults supply them. Expect stored price 12.35, quantity 2, and t for both defaults. numeric(5,2) stores two fractional digits, so decimal exactness does not mean it preserves arbitrary input scale.