A virtual generated column defines an expression that is evaluated when the row is read. In PostgreSQL 18, virtual is also the default kind of generated column.
The demo changes quantity and recomputes total without a separate update. Reads pay the computation cost, so compare it with a stored generated column for the workload.
When to use
Use it when a value can always be derived from other columns and should stay consistent.