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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.