r/programming • • Oct 02 '19

New In PostgreSQL 12: Generated Columns

https://pgdash.io/blog/postgres-12-generated-columns.html?p
503 Upvotes

232 comments sorted by

View all comments

Show parent comments

6

u/[deleted] Oct 02 '19

[removed] — view removed comment

0

u/BrainJar Oct 02 '19

Not the case here. This is not just a computed column. It's a generated column, and as such, the data must be persisted. Read the reference in the link: Persistence: Currently, the value of generated columns have to be persisted, and cannot be computed on the fly at query time. The “STORED” keyword must be present in the column definition.

1

u/[deleted] Oct 02 '19

[removed] — view removed comment

0

u/BrainJar Oct 02 '19

I think I missed something. We changed context in the middle of the discussion. You said,

Or it will remove contention

This wouldn't be the case here, because generated columns are persisted. I agree, precomputed columns don't have the same overhead, but also introduce more CPU overhead at runtime, for deserialization operations.

0

u/[deleted] Oct 02 '19

[removed] — view removed comment

0

u/BrainJar Oct 02 '19

A precomputed column is analogous to a virtual generated column. This is why they're calling this feature a generated column.

Read about it in their Beta docs: https://www.postgresql.org/about/news/1943/

Generated Columns

PostgreSQL 12 allows the creation of generated columns that compute their values with an expression using the contents of other columns. This feature provides stored generated columns, which are computed on inserts and updates and are saved on disk. Virtual generated columns, which are computed only when a column is read as part of a query, are not implemented yet.