06, 11 chapters
types and values
everything.types
types and values
numbers, text, time, json, arrays and ranges. picking the type is half the schema.
- 06.01types and castsevery value has a type. ::, implicit casts, and why '1' + 1 works but 1 || 1 doesn't.
- 06.02integers, numeric and floatsint vs bigint, numeric for money, and 0.1 + 0.2 in float8 vs numeric.
- 06.03text, varchar and collationswhy varchar(255) is a habit from another database, and why 'B' sorts before 'a' here.
- 06.04dates, times and intervalsdate arithmetic, interval math across month ends, and date_trunc for grouping by week.
- 06.05timestamptz and time zonesit stores an instant, not a zone. and the hour in march that never happened.
- 06.06booleans, enums and domainsa boolean with three values, enums you can grow but not shrink, and domains as reusable rules.
- 06.07identity columns and uuidswhy serial is legacy, GENERATED AS IDENTITY, and uuidv7 keys that sort by time.
- 06.08arraysa list in a column. ANY, unnest, @>, and the day it should have been a table.
- 06.09json and jsonba document in a column. ->, ->>, @>, jsonpath, JSON_TABLE, and why jsonb won.
- 06.10range typesa start and an end as one value. overlaps with &&, empty ranges, and multiranges.
- 06.11generated columnscolumns computed from other columns. stored vs virtual, and why postgres 18 made virtual the default.