gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

48 行
5.3KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>7.6. LIMIT and OFFSET</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="queries-order.html" title="7.5. Sorting Rows" /><link rel="next" href="queries-values.html" title="7.7. VALUES Lists" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">7.6. <code xmlns="http://www.w3.org/1999/xhtml" class="literal">LIMIT</code> and <code xmlns="http://www.w3.org/1999/xhtml" class="literal">OFFSET</code></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="queries-order.html" title="7.5. Sorting Rows">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="queries.html" title="Chapter 7. Queries">Up</a></td><th width="60%" align="center">Chapter 7. Queries</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="queries-values.html" title="7.7. VALUES Lists">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="QUERIES-LIMIT"><div class="titlepage"><div><div><h2 class="title" style="clear: both">7.6. <code class="literal">LIMIT</code> and <code class="literal">OFFSET</code></h2></div></div></div><a id="id-1.5.6.10.2" class="indexterm"></a><a id="id-1.5.6.10.3" class="indexterm"></a><p>
  3. <code class="literal">LIMIT</code> and <code class="literal">OFFSET</code> allow you to retrieve just
  4. a portion of the rows that are generated by the rest of the query:
  5. </p><pre class="synopsis">
  6. SELECT <em class="replaceable"><code>select_list</code></em>
  7. FROM <em class="replaceable"><code>table_expression</code></em>
  8. [<span class="optional"> ORDER BY ... </span>]
  9. [<span class="optional"> LIMIT { <em class="replaceable"><code>number</code></em> | ALL } </span>] [<span class="optional"> OFFSET <em class="replaceable"><code>number</code></em> </span>]
  10. </pre><p>
  11. </p><p>
  12. If a limit count is given, no more than that many rows will be
  13. returned (but possibly fewer, if the query itself yields fewer rows).
  14. <code class="literal">LIMIT ALL</code> is the same as omitting the <code class="literal">LIMIT</code>
  15. clause, as is <code class="literal">LIMIT</code> with a NULL argument.
  16. </p><p>
  17. <code class="literal">OFFSET</code> says to skip that many rows before beginning to
  18. return rows. <code class="literal">OFFSET 0</code> is the same as omitting the
  19. <code class="literal">OFFSET</code> clause, as is <code class="literal">OFFSET</code> with a NULL argument.
  20. </p><p>
  21. If both <code class="literal">OFFSET</code>
  22. and <code class="literal">LIMIT</code> appear, then <code class="literal">OFFSET</code> rows are
  23. skipped before starting to count the <code class="literal">LIMIT</code> rows that
  24. are returned.
  25. </p><p>
  26. When using <code class="literal">LIMIT</code>, it is important to use an
  27. <code class="literal">ORDER BY</code> clause that constrains the result rows into a
  28. unique order. Otherwise you will get an unpredictable subset of
  29. the query's rows. You might be asking for the tenth through
  30. twentieth rows, but tenth through twentieth in what ordering? The
  31. ordering is unknown, unless you specified <code class="literal">ORDER BY</code>.
  32. </p><p>
  33. The query optimizer takes <code class="literal">LIMIT</code> into account when
  34. generating query plans, so you are very likely to get different
  35. plans (yielding different row orders) depending on what you give
  36. for <code class="literal">LIMIT</code> and <code class="literal">OFFSET</code>. Thus, using
  37. different <code class="literal">LIMIT</code>/<code class="literal">OFFSET</code> values to select
  38. different subsets of a query result <span class="emphasis"><em>will give
  39. inconsistent results</em></span> unless you enforce a predictable
  40. result ordering with <code class="literal">ORDER BY</code>. This is not a bug; it
  41. is an inherent consequence of the fact that SQL does not promise to
  42. deliver the results of a query in any particular order unless
  43. <code class="literal">ORDER BY</code> is used to constrain the order.
  44. </p><p>
  45. The rows skipped by an <code class="literal">OFFSET</code> clause still have to be
  46. computed inside the server; therefore a large <code class="literal">OFFSET</code>
  47. might be inefficient.
  48. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="queries-order.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="queries.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="queries-values.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">7.5. Sorting Rows </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 7.7. <code class="literal">VALUES</code> Lists</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1