生成列是一个列,其值是从其他列自动计算而来,而不是直接插入。PostgreSQL 支持存储生成列(Postgres 12+)— 计算值在写入时计算并存储。它们自动保持派生数据的一致性。
定义生成列
products (
id SERIAL ,
price ,
quantity ,
total GENERATED ALWAYS (price quantity) STORED
);
products (price, quantity) (, );
total products;
