0
0
PostgreSQLquery~5 mins

GENERATED columns (stored and virtual) in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a GENERATED column in PostgreSQL?
A GENERATED column is a special column in a table whose value is automatically computed from other columns using an expression. PostgreSQL only supports stored generated columns.
Click to reveal answer
intermediate
What is a stored GENERATED column in PostgreSQL?
A stored GENERATED column saves the computed value physically in the table. Virtual GENERATED columns are not supported.
Click to reveal answer
beginner
How do you define a stored GENERATED column in PostgreSQL?
Use the syntax: <column_name> data_type GENERATED ALWAYS AS (expression) STORED. The expression calculates the value stored in the column.
Click to reveal answer
beginner
Can you insert or update values directly into a GENERATED column?
No, you cannot insert or update values directly into a GENERATED column because its value is always computed automatically from the expression.
Click to reveal answer
intermediate
Why might you choose a stored GENERATED column?
Stored GENERATED columns improve query performance because values are precomputed and saved, but they use more storage. Virtual columns are not supported in PostgreSQL.
Click to reveal answer
Which keyword is required to define a stored GENERATED column in PostgreSQL?
ASTORED
BVIRTUAL
CCOMPUTED
DCALCULATED
Can you manually insert a value into a GENERATED column?
AOnly if it is virtual
BNo, values are computed automatically
CYes, always
DOnly if the column is nullable
What happens when you query a GENERATED column in PostgreSQL?
AThe value is computed on the fly
BThe query fails
CThe value is retrieved from stored data
DThe value is null
Which of these is a benefit of stored GENERATED columns?
AFaster query performance
BLess disk space used
CValues can be manually changed
DNo need to define an expression
Which PostgreSQL version introduced support for stored GENERATED columns?
A9.6
B10
C13
D12
Explain what a GENERATED column is and how it works (stored vs virtual concept, noting PostgreSQL support).
Think about when the value is calculated and where it is saved.
You got /4 concepts.
    Describe how to create a stored GENERATED column in PostgreSQL with an example.
    Focus on the exact keywords and structure.
    You got /3 concepts.