severndigital Posted February 25, 2011 Share Posted February 25, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/228811-want-to-store-equation-result-into-table/ Share on other sites More sharing options...
btherl Posted April 14, 2011 Share Posted April 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/228811-want-to-store-equation-result-into-table/#findComment-1201347 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.