I have a Rectangle
entity in my database with the following attributes:
CREATE TABLE Rectangle (
Id INTEGER PRIMARY KEY NOT NULL,
SideA INTEGER NOT NULL,
SideB INTEGER NOT NULL,
Area INTEGER
);
In the moment I insert my data, Area
can be not specified. Whenever I press a "Update Area" button in my Java Application the Area
value will be updated.
Now, if SideA
is edited while using the application, I would like Area
to be edited consequently at the same time. How to make an attribute of an entity dependent from others and be updated in real time? Is it possible without using a pattern observer at Java level but using specific keywords in postgres / SQL?
EDIT: As I noticed most of answers are asking me the same question I'll add this small note.
The real database I'm managing is actually needing to calculate the mass of galaxy using some parameters from both the Galaxy
table and other related tables. It needs to store the mass of thousands of galaxies and the application will display them in groups of 100. Since displaying the mass list is a frequent action, while updating one of those values is happening very seldom, I decided to calculate all values once and to store them in the database. I know it's a redundant information, but IMHO in this situation is worth it.