分页查询
最近更新时间: 2025-02-18 16:02:00
- 默认从第一条开始,返回一条记录。
postgres=# select * from tbase limit 1;
id | nickname
----+-------------
1 | hello TDSQL PG
(1 row)
- 使用offset指定从第几条开始,0表示第一条开如,返回1条记录。
postgres=# select * from tbase limit 1 offset 0;
id | nickname
----+-------------
1 | hello TDSQL PG
(1 row)
- 从第3条开始,返回二条记录。
postgres=# select * from tbase limit 1 offset 2;
id | nickname
----+-----------------------------
1 | TDSQL PG分布式数据库的时代来了
(1 row)
- 上面的语句没有使用排序,返回结果不可预知,使用order by可以获得一个有序的结果。
postgres=# select * from tbase order by id limit 1 offset 2;
id | nickname
----+-----------
2 | TDSQL PG好
(1 row)