
Tech
PostgreSQL Generated Column vs Trigger: Which to Use for a Derived Column
Disclosure: I build Schemity , a desktop ERD tool - this post is from our blog and uses it for the examples.
TL;DR: Use a generated column when the value comes from other columns in the same row through immutable functions, because the database guarantees it and nobody can write to it. Use a trigger only when the value needs another table, the current time, or a function PostgreSQL does not call immutable. On PostgreSQL 18 a generated column is virtual unless you write STORED , and a v...
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to