postgresql 使用limit分页

来源:互联网 发布:软件开发培训费用 编辑:程序博客网 时间:2024/05/17 03:14
SELECT select_list    FROM table_expression    [ ORDER BY ... ]    [ LIMIT { number | ALL } ] [ OFFSET number ]
举例:
select * from userinfo limit 10 offset 3 选出的是4-13条记录。没有经过orderby,多次执行语句可能结果不同;经过orderby则结果相同。
If a limit count is given, no more than that many rows will be returned.
返回不多于limit的条数
OFFSET says to skip that many rows before beginning to return rows.
跳过前offset条数
If both OFFSET and LIMIT appear, then OFFSET rows are skipped before starting to count the LIMIT rows that are returned.
二者一起用时offset跳过后开始数limit
using different LIMIT/OFFSET values to select different subsets of a query result will give inconsistent results unless you enforce a predictable result ordering with ORDER BY. This is not a bug; it is an inherent consequence of the fact that SQL does not promise to deliver the results of a query in any particular order unless ORDER BY is used to constrain the order.
只用offset和limit会导致多次查询结果不同,用orderby可以避免,但是这不是bug
	
				
		
原创粉丝点击