A generated column is a column whose value is computed automatically from other columns, rather than being inserted directly. PostgreSQL supports stored generated columns (Postgres 12+) — the computed value is calculated on write and stored. They keep derived data consistent automatically.
Defining a generated column
products (
id SERIAL ,
price ,
quantity ,
total GENERATED ALWAYS (price quantity) STORED
);
products (price, quantity) (, );
total products;
