PostgreSQL Generated Columns
In this tutorial, you will learn about PostgreSQL generated columns whose values are automatically calculated from other columns.
In PostgreSQL, a generated column is a special type of column whose values are automatically calculated based on expressions or values from other columns.
A generated column is referred to as a computed column in the SQL Server
or a virtual column in Oracle
.
There are two kinds of generated columns:
Stored: A stored generated column is calculated when it is inserted or updated and occupies storage space.
Virtual: A virtual generated column is computed when it is read and does not occupy storage space.
A virtual generated column is like a view, whereas a stored generated column is similar to a materialized view. Unlike a material view, PostgreSQL automatically updates data for stored generated columns.
PostgreSQL currently implements only stored generated columns.