i have the following
+----------+----------+ | a | b | | numeric | numeric | +----------+----------+ | 10 | 10 | +----------+----------+ | 10 | 10 | +----------+----------+
I want to have something like that
select *, a+b as mes
from maths;
but to have a column sum
and evrytime the columns a and b
get update calculate the new sum in columns sum
i try this and i get the following error
Advertisement
Answer
The syntax for generated column in PostgreSQL is:
alter table maths add column kostas int generated always as (a + b) stored;
Demo: https://dbfiddle.uk/?rdbms=postgres_12&fiddle=7f328dbdb991e68b46a8292bf7c480ab