title: How to paginate without fetching the entire table?
body: <p>I am trying to <strong>paginate</strong> the fetched data from my <em>table</em>(from <em>Remote Database on <strong>Azure</em></strong>) as can be seen in the code, below:</p>
  
  <pre><code>    import json
      import pyodbc
  
      # Includes other imports
  
      def query_db(query):
          """
          Function that queries the required table in the DB
          """
  
          cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server}; \
                                 SERVER=db.database.windows.net; \
                                 DATABASE=DB; UID=id; PWD=pwd')
          cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
          cur = cnxn.cursor()
          cur.execute(query)
  
          # Fetches the entire table ## This is causing the lagg
          r = [dict( (cur.description[i][0], value) for i, value in enumerate(row) ) for row in cur.fetchall()]
  
          cur.connection.close()
  
          return(r)
  
      @api_view(['GET'])
      def get(request):
          paginator = PageNumberPagination()
          my_query = query_db("select * from Client_Table")
  
          result_page = paginator.paginate_queryset(my_query, request)
          json_output = json.dumps(result_page, cls=DjangoJSONEncoder)
  
          return paginator.get_paginated_response(json_output)
  </code></pre>
  
  <p>The Problem here being: I am fetching the entire table first, and then paginating it. How do I <em>Paginate</em>, without having to fetch the entire table ?
  <em>NOTE: I am not using Django Models</em></p>