I created the generated column "available_quantity" -
alter table products_regions
add column available_quantity int8
GENERATED ALWAYS AS (quantity_total - quantity_ordered) STORED;
When performing some logic, only the "quantity_ordered" column changes.
But I get an
ERROR: the column "available_quantity" can only be assigned the DEFAULT value. The column "available_quantity" is generated.
I don't write anything directly into this field.
If you change the "quantity_ordered" field in the database manually, then "available_quantity" is calculated
How can I solve the problem?
CodePudding user response:
The solution has been found.
If there is a calculated field in the Postgresql database and ORM Hibernate, then at the entity level it is required to specify an
@Column for this field (name = "your name", inserted = false, updated = false).
CodePudding user response:
You cannot modify a generated column. The documentation is pretty clear about that:
A generated column cannot be written to directly. In
INSERT
orUPDATE
commands, a value cannot be specified for a generated column, but the keywordDEFAULT
may be specified.
Use a regular column and fill it with a trigger during INSERT
.