I only tested this in Rails 4, but there is an interesting way to use a range with a where hash to get this behavior.
User.where(id: 201..Float::INFINITY)
will generate SQL
SELECT 'users'.* FROM 'users' WHERE ('users'.'id' >= 201)
The same can be done for less than with -Float::INFINITY .
I just posted a similar question asking to do this with dates here on SO .
>= against >
So that people do not dig and do not follow the comments, here are the main points.
The method above only generates the request >= and not > . There are many ways to deal with this alternative.
For discrete numbers
You can use the strategy number_you_want + 1 as described above, where I am interested in users with id > 200 but actually looking for id >= 201 . This is good for integers and numbers, where you can increase by a unit of interest.
If you have a number extracted into a well-named constant, this might be easiest to read and understand at a glance.
Inverted logic
We can use the fact that x > y == !(x <= y) and use the where not chain.
User.where.not(id: -Float::INFINITY..200)
which generates SQL
SELECT 'users'.* FROM 'users' WHERE (NOT ('users'.'id' <= 200))
It takes an extra second to read and ponder, but will work for non-discrete values ββor columns where you cannot use the + 1 strategy.
Arel table
If you want to become trendy, you can use Arel::Table .
User.where(User.arel_table[:id].gt(200))
will generate SQL
"SELECT 'users'.* FROM 'users' WHERE ('users'.'id' > 200)"
Features are as follows:
User.arel_table
This approach will help you get exactly the SQL that interests you, but not many people use the Arel table directly and may find it confusing and / or confusing. You and your team will know what is best for you.
bonus
Starting with Rails 5, you can also do this with dates!
User.where(created_at: 3.days.ago..DateTime::Infinity.new)
will generate SQL
SELECT 'users'.* FROM 'users' WHERE ('users'.'created_at' >= '2018-07-07 17:00:51')
Double Bonus
After the release of Ruby 2.6 (December 25, 2018), you can use the new endless range syntax! Instead of 201..Float::INFINITY you can just write 201.. More information in this post .