I re-formatted your example code to try and understand it more easily:
select round(
round(
sum(
case
when acct_no = '2999'
and date between '1/1/14' and current_date then amount
end )::numeric,
4 )::float
/ round(
sum(
case
when acct_no = '3989'
and date between '1/1/14' and current_date then amount
end )::numeric,
4 )::numeric,
4 ) column
from table
The problem is that you're casting the numerator of your division operation as a float
data type, which, because you didn't specify a precision, is equivalent to double precision
.
round(
sum(
case
when acct_no = '2999'
and date between '1/1/14' and current_date then amount
end )::numeric,
4 )::float
/ round(
sum(
case
when acct_no = '3989'
and date between '1/1/14' and current_date then amount
end )::numeric,
4 )::numeric
So the result of the expression is a double precision
value instead of as a numeric
value, hence the error you observed.