Re:New In Postgres 12: Generated Columns
by victor106 on Wednesday October 02, 2019 @09:16AM
(#21136032)
Very Interesting. Never heard this before.
Can you give some examples of what would constitute declarative business logic vs imperative business logic?
Declarative programming expresses the logic of a computation without describing its control flow.
This new feature in PostgreSQL is a great example of that: generated columns (declarative logic) were introduced to reduce the need for triggers (imperative logic).
In SQL, declarative logic consists of constraints, indexes, views, and prepared statements. They can significantly increase the efficiency and reliability of the entire system. Imperative logic is mostly triggers and stored procedures, both of which can become hard to maintain and scale.
The trick is to keep declarative business logic in the database layer, and imperative business logic in the application layer.
This allows a large team of developers to move quickly without breaking things.