I created a table named Loan that contains the following columns:
loanID SERIAL,
annualInterestRate INT,
numberOfYears INT,
loanAmount NUMERIC,
monthlyPayment NUMERIC
The calculation of the monthlyPayment depends on numberOfYears, loanAmount, and the annualInterestRate as per the following formula:
monthlyPayment = (loanAmount * monthlyInterestRate) /
(1 - (1/Math.pow(1 + monthlyInterestRate , numberOfYears * 12) ));
I made a function named get_monthly_payment() that returns the monthlyPayment with no problem. For each row, I want to make the return of this function the default of the column monthlyPayment.
How can I achieve this?