[英]Why LIMIT и OFFSET (OFFSET ... ROWS FETCH FIRST ... ROW only) functions in PostgreSQL are not working?
I am trying to use LIMIT and OFFSET functions or OFFSET... ROWS FETCH FIRST... ROW only.我正在尝试使用 LIMIT 和 OFFSET 函数或 OFFSET...ROWS FETCH FIRST...仅行。 PostgreSQL gives me the wrong number of rows in result.
PostgreSQL 结果中的行数错误。
select user_id, max(order_ts) as lastorder
from production.orders
group by user_id
order by lastorder desc, user_id desc
OFFSET 10 ROWS
FETCH FIRST 20 ROW only
or或者
select user_id, max(order_ts) as lastorder
from production.orders
group by user_id
order by lastorder desc, user_id desc
OFFSET 10
limit 20
Still gives me 20 rows (should be 10: from 10th row to 20th - is 10).仍然给我 20 行(应该是 10:从第 10 行到第 20 行 - 是 10)。
How is this?这怎么样? Any help, please?
有什么帮助吗?
LIMIT 20
tells server to return not more than 20 records. LIMIT 20
告诉服务器返回不超过 20 条记录。 FETCH FIRST 20 ONLY
is absolutely the same. FETCH FIRST 20 ONLY
是完全一样的。 The query might return 20 rows or less depending on the data and query conditions.根据数据和查询条件,查询可能返回 20 行或更少。 If you are trying to get rows from 11th to 20th then you need to specify
LIMIT 10 OFFSET 10
.如果您尝试获取第 11 到第 20 行,则需要指定
LIMIT 10 OFFSET 10
。
See the paragraph LIMIT Clause in the documentation for details: https://www.postgresql.org/docs/15/sql-select.html#SQL-LIMIT有关详细信息,请参阅文档中的LIMIT 子句段落: https://www.postgresql.org/docs/15/sql-select.html#SQL-LIMIT
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.