获取 Postgresql 中的第 N 行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2082835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:59:19  来源:igfitidea点击:

Get the Nth row in Postgresql

postgresql

提问by Byron Whitlock

In MySQL I can do SELECT * FROM tbl LIMIT 10

在 MySQL 我可以做 SELECT * FROM tbl LIMIT 10

In MSSQL I can do SELECT TOP 5 * FROM tbl

在 MSSQL 我可以做 SELECT TOP 5 * FROM tbl

How do I do this in Postgresql?

我如何在 Postgresql 中做到这一点?

回答by Dirk

See the LIMITclause:

LIMIT条款

SELECT * FROM tbl LIMIT 10

or

或者

SELECT * FROM tbl OFFSET 20

and, of course

而且当然

SELECT * FROM tbl LIMIT 10 OFFSET 10

回答by Bob Jarvis - Reinstate Monica

From the PostgreSQL docs:

来自 PostgreSQL 文档:

SELECT select_list
  FROM table_expression
  [ ORDER BY ... ]
  [ LIMIT { number | ALL } ] [ OFFSET number ]

So LIMIT should work as it does in MySQL. OFFSET is used to skip rows before starting to return data.

所以 LIMIT 应该像在 MySQL 中一样工作。OFFSET 用于在开始返回数据之前跳过行。

See docs for LIMIT and OFFSET

请参阅LIMIT 和 OFFSET 的文档

I hope this helps.

我希望这有帮助。

回答by Jakob Borg

The syntax you quote for MySQL should work just fine for Postgresql as well. Doesn't it?

您为 MySQL 引用的语法也适用于 Postgresql。不是吗?