I wanna add a generated column in my PostgreSQL table. The problem is when I use operation with parenthesis, I got zero results.
ALTER TABLE my_table
add COLUMN my_column decimal(4,3) GENERATED ALWAYS AS ((price-buy_price)/price) STORED;
All the result in my_column is 0.000. Then I try to avoid the parenthesis in my operation so my query looks like:
ALTER TABLE my_table
add COLUMN my_column2 decimal(4,3) GENERATED ALWAYS AS (price-buy_price/price) STORED;
That's work but the result is not what I want. I wonder why it fails every time I use parenthesis and it works when I do operations like (a+b) or (a+b/c) or (a*b-c/d) etc.
Is anyone has the solution? Thank you.
(1.0 * (price-buy_price)/price)solves it: dbfiddle.uk/…