title: how to apply LIMIT/OFFSET on large table in sqlalchemy while getting intermediate result as well [please read the details below]?
body: <p>I want to do 3 operations on a table which contains large number of records: (1)<code>filter</code> (based on a search query) (2)<code>order_by</code> (on a single column in asc/desc) and (3)<code>slice</code> (for given <code>offset</code> and <code>limit</code> values).</p>
  
  <p>While carrying out these operations I need the intermediate result (obtained after filtering/sorting), to find out the number of records which satisfied the given filter query (to send this information to the front-end).</p>
  
  <p>Right now I am using <code>FILTER</code> and <code>ORDER_BY</code> of sqlalchemy to get the intermediate result and then applying slicing on the list. How can I achieve the same using sqlalchemy's <code>FILTER</code>, <code>ORDER_BY</code> and <code>SLICE</code> together along with getting the number of records after filtering/sorting as a sub-result?</p>
  
  <p>The sqlalchemy query I am using right now is as follows:</p>
  
  <pre><code>result = session.\
           query(Customer).\
           filter(Customer.name.like('%' + filter_query + '%') | Customer.email.like('%' + filter_query + '%') | Customer.partner.like('%' + filter_query + '%')).\
           order_by(asc(getattr(Customer, sorting_column_name))).\
           all()
  </code></pre>