Store a formula in a table and use the formula in a function
12
votes
3
answers
12910
views
I have a PostgreSQL 9.1 database where part of it handles agent commissions. Each agent has his/her own formula of calculation how much commission they get. I have a function to generate the amount of commission each agent should get, but it's becoming impossible to use as the number of agents grow. Am forced to do some extremely long case statements and repeating code, which has made my function very big.
All the formulas have constant variables:
d .. days worked that month r .. new nodes accuired l .. loyalty score s .. subagent commission b .. base rate i .. revenue gainedThe formula can be something like: d*b+(l*4+r)+(i/d)+s Each agent negotiates the payment formula with the HR dept. So can I store the formula in the agents table then have like a small function that just gets the formula from the table and translates it with values and computes the amount?
Asked by indago
(545 rep)
Jan 31, 2013, 10:30 AM
Last activity: Apr 1, 2023, 12:06 PM
Last activity: Apr 1, 2023, 12:06 PM