1

What's the idiomatic way to achieve the below without reproducing the expression yielding the non-integer value (in my real case the value is computed as a percentage following a lengthy query which I don't want to reproduce):

SELECT * FROM SomeTable WHERE 1/100.0 >0 AND 1/100.0<=0.5

I am interested in a generalized pattern that can accommodate all type of boundaries: [], [), (] and ().

2
  • 1
    Your code really doesn't make sense. I'm going to assume that you want that expression in the where clause, not the select clause. Oct 5, 2014 at 17:27
  • @GordonLinoff you are right; I updated the question Oct 5, 2014 at 17:42

2 Answers 2

1

If you don't want to rewrite the expression, then use a subquery:

select t.*
from (select 1/100.0 as x
      . . .
     ) t
where x > 0 and x <= 0.5

For the special case of equality as both nds, then you can use between:

where 1/100.0 between 0 and 0.5
0

You can construct the range and check whether it contains your value:

SELECT * FROM SomeTable WHERE numrange(0,0.5,'(]') @> 1/100.0;
2
  • it appears that this is not available in PostgreSQL 9.1 Oct 5, 2014 at 18:08
  • Sorry for not looking at your tags, indeed, they appeared in 9.2 first.
    – vyegorov
    Oct 5, 2014 at 18:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.