Jump to content

want to store equation result into table


severndigital

Recommended Posts

I want to have a field in my table called

'after_reserves'

 

I want this field to always store the result of an equation on two other fields called 'inv_count' and 'total_reserves'

 

Is is possible to store the result of an equation automatically?

When I add the column and cast the type, I was thinking it would look something like this.

 

ALTER TABLE inv_items ADD COLUMN after_reserves integer SET DEFAULT (inv_count - total_reserves)

 

...

When I do a select I just want to do this

 

SELECT after_reserves FROM inv_items WHERE id ='54';

 

and I want it to automatically return inv_count - total_reserves

 

Can it be done?

 

Thanks in advance..

  • 1 month later...

The simplest way to do this is just to select inv_count - total_reserves, rather than making a new column.  If you are integrating with existing software that needs the after_reserves column, then you could make a trigger that updates that column whenever the values it depends on change.  Or you could create a view into that table, with the after_reserves column defined as inv_count - total_reserves.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.