skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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).


  2. You cannot modify a generated column. The documentation is pretty clear about that:

    A generated column cannot be written to directly. In INSERT or UPDATE commands, a value cannot be specified for a generated column, but the keyword DEFAULT may be specified.

    Use a regular column and fill it with a trigger during INSERT.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search