Why production code shouldn't say SELECT *
SELECT * is fine in psql for exploration. In production code it's a bug waiting to happen:
- Pulls every column over the network — wasted bandwidth.
- Defeats covering indexes — the planner can't pick an index-only scan when it has to fetch all columns.
- Breaks subtly when columns are added or reordered — code that assumed the third column was X now reads Y.
- Obscures intent — the reader can't tell which fields the query depends on.
The rule
Production code lists explicit columns. Migrations and one-shot scripts can use SELECT *. ORMs that select all columns by default are sometimes acceptable because the mapping is type-checked — but if the table has a 4MB JSONB column you read once a month, that's now in every fetch.