Reputation: 51
I have created a view which has a simple query
create or replace view temp(EFTSLOAD, UOC, CODE) as
select eftsload, uoc,code from subjects where
cast (eftsload as numeric(5,3)) != cast((uoc/48) as numeric(5,3));
But my query select * from temp; gives me rows like
eftsload | uoc | code
0.125 6 ECONXXXX
0.5 24 HISTXXXX
The condition says eftsload != uoc/48 but I get rows where efts = 0.125 and uoc =6 which a violation as 6/48=0.125 and many other instances where the relation eftsload != uoc/48 is clearly not true
Why does this happen?
Upvotes: 0
Views: 67
Reputation: 520878
One possibility is that the quantity uoc/48
is being treated as integer division, and then afterwards the truncated quotient is being cast to a numeric floating point. But you really want to do floating point division here.
Try this:
select eftsload, uoc, code
from subjects
where cast(eftsload as numeric(5,3)) != uoc / 48::numeric(5,3)
Upvotes: 2