0

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?

4
  • 1
    I can't read that text... Formatted text please, not images. Commented May 2, 2017 at 7:39
  • Please read meta.stackoverflow.com/questions/285551/… and the accepted answer Commented May 2, 2017 at 7:40
  • eftslaod in definition and efts in columns. Commented May 2, 2017 at 7:45
  • did not know that I couldnt use images Thanks. I hope this is suficient to understand my question Commented May 2, 2017 at 7:52

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

1 Comment

That's it. Its not giving me those values anymore. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.