标签:
(based in postgresql )
LIMIT: if a limit count is given , no more than taht many rows be returned (but possibly less, if query itself yields less rows)
OFFSET: OFFSET says to skip that many rows before beginning to return rows to the client. OFFSET 0 is the same as omitting the OFFSETclause. If both OFFSET and LIMIT appear, then OFFSET rows are skipped before starting to count the LIMIT rows that are returned.
SELECT select_list
FROM table_expression
[LIMIT { number | ALL }] [OFFSET number]
FETCH:retrieve rows from a query using a cursor
FETCH [ direction { FROM | IN } ] cursorname where direction can be empty or one of: NEXT PRIOR FIRST LAST ABSOLUTE count RELATIVE count count ALL FORWARD FORWARD count FORWARD ALL BACKWARD BACKWARD count BACKWARD ALL
about direction parameters information in : http://www.postgresql.org/docs/8.1/static/sql-fetch.html
pagination:
PAGINATION_LIMIT = 20
offset = get_http_argument(‘offset‘, optional=True) or 1 offset = int(offset) offset = offset if offset > 0 else 1 limit = PAGINATION_LIMIT offset = (offset-1)*limit result = db().list(‘‘‘SELECT *, COUNT(*) OVER() AS total_rows
FROM test OFFSET %(offset)s FETCH FIRST %(limit) ROWS ONLY ‘‘‘, offset=offset, limit=limit)
total_pages = total_rows/limit
You can get different results by request a different page :
{% if total_pages > 1 %} <div class="pagination pagination-centered mt-10"> <ul class="clearfix inline-block"> {% if offset > 6 %} <li><a href="javascript:void(0)">1</a></li> <li><a class="disabled" href="javascript:void(0);">...</a></li> {% endif %} {% for i in range(offset - 5, offset) %} {% if i > 0 %} <li class="inline-block"><a href="javascript:void(0);">{{ i }}</a></li>{% endif %} {% endfor %} <li class="current inline-block"><a class="current" href="javascript:void(0);">{{ offset }}</a></li> {% for i in range(5) %} {% if offset + loop.index <= total_pages %} <li class="inline-block"><a href="javascript:void(0);">{{ offset + loop.index }}</a></li>{% endif %} {% endfor %} {% if total_pages > offset + 5 %} <li><a class="disabled" href="javascript:void(0)">...</a></li> <li> <a href="javascript:void(0)">{{ total_pages |int }}</a> </li> {% endif %} </ul> </div> {% endif %}
pagination -limit & offset (python)
标签:
原文地址:http://www.cnblogs.com/ChaserChen/p/4823580.html