title: Rails ActiveRecord query with where clause including a bound of a Postgresql tsrange data type
body: <p>I have a Rails model that has an attribute (named <code>when</code>) that is a tsrange data type (a stored range of two datetimes in a single column) and I would like to write a query that returns rows with a lower bound of the tsrange that are > now (so, events starting in the future).</p>
  
  <p>Rails gives the helper methods <code>begin</code> and <code>end</code> that can be used on serialized objects but I would prefer to have the database handle this sorting (as opposed to ruby).   The ruby implementation is:</p>
  
  <pre><code>Event.select {|e| e.when.begin &gt; Time.now}
  </code></pre>
  
  <p>The below SQL statement executes what I'm looking for but I can't figure out how to produce a similar result using ActiveRecord directly.</p>
  
  <pre><code>ActiveRecord::Base.connection.execute("SELECT events.* FROM events WHERE lower(events.when) &gt;= NOW()")
  </code></pre>
  
  <p>I'm using</p>
  
  <ul>
  <li>Rails 4.0.1</li>
  <li>ruby-2.0.0-p247</li>
  <li>psql (9.2.4)</li>
  </ul>
  
  <p>EDIT:</p>
  
  <p>Here's one way that gets closer but still requires writing out SQL and embedding <code>now</code> into the sql as opposed to using a ruby object:</p>
  
  <pre><code>Event.where("lower(events.when) &gt;= NOW()")
  </code></pre>