gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
11KB

  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>9.19. Range Functions and Operators</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="functions-array.html" title="9.18. Array Functions and Operators" /><link rel="next" href="functions-aggregate.html" title="9.20. Aggregate Functions" /></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">9.19. Range Functions and Operators</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="functions-array.html" title="9.18. Array Functions and Operators">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="functions.html" title="Chapter 9. Functions and Operators">Up</a></td><th width="60%" align="center">Chapter 9. Functions and Operators</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="functions-aggregate.html" title="9.20. Aggregate Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="FUNCTIONS-RANGE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">9.19. Range Functions and Operators</h2></div></div></div><p>
  3. See <a class="xref" href="rangetypes.html" title="8.17. Range Types">Section 8.17</a> for an overview of range types.
  4. </p><p>
  5. <a class="xref" href="functions-range.html#RANGE-OPERATORS-TABLE" title="Table 9.53. Range Operators">Table 9.53</a> shows the operators
  6. available for range types.
  7. </p><div class="table" id="RANGE-OPERATORS-TABLE"><p class="title"><strong>Table 9.53. Range Operators</strong></p><div class="table-contents"><table class="table" summary="Range Operators" border="1"><colgroup><col /><col /><col /><col /></colgroup><thead><tr><th>Operator</th><th>Description</th><th>Example</th><th>Result</th></tr></thead><tbody><tr><td> <code class="literal">=</code> </td><td>equal</td><td><code class="literal">int4range(1,5) = '[1,4]'::int4range</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&lt;&gt;</code> </td><td>not equal</td><td><code class="literal">numrange(1.1,2.2) &lt;&gt; numrange(1.1,2.3)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&lt;</code> </td><td>less than</td><td><code class="literal">int4range(1,10) &lt; int4range(2,3)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&gt;</code> </td><td>greater than</td><td><code class="literal">int4range(1,10) &gt; int4range(1,5)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&lt;=</code> </td><td>less than or equal</td><td><code class="literal">numrange(1.1,2.2) &lt;= numrange(1.1,2.2)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&gt;=</code> </td><td>greater than or equal</td><td><code class="literal">numrange(1.1,2.2) &gt;= numrange(1.1,2.0)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">@&gt;</code> </td><td>contains range</td><td><code class="literal">int4range(2,4) @&gt; int4range(2,3)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">@&gt;</code> </td><td>contains element</td><td><code class="literal">'[2011-01-01,2011-03-01)'::tsrange @&gt; '2011-01-10'::timestamp</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&lt;@</code> </td><td>range is contained by</td><td><code class="literal">int4range(2,4) &lt;@ int4range(1,7)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&lt;@</code> </td><td>element is contained by</td><td><code class="literal">42 &lt;@ int4range(1,7)</code></td><td><code class="literal">f</code></td></tr><tr><td> <code class="literal">&amp;&amp;</code> </td><td>overlap (have points in common)</td><td><code class="literal">int8range(3,7) &amp;&amp; int8range(4,12)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&lt;&lt;</code> </td><td>strictly left of</td><td><code class="literal">int8range(1,10) &lt;&lt; int8range(100,110)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&gt;&gt;</code> </td><td>strictly right of</td><td><code class="literal">int8range(50,60) &gt;&gt; int8range(20,30)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&amp;&lt;</code> </td><td>does not extend to the right of</td><td><code class="literal">int8range(1,20) &amp;&lt; int8range(18,20)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">&amp;&gt;</code> </td><td>does not extend to the left of</td><td><code class="literal">int8range(7,20) &amp;&gt; int8range(5,10)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">-|-</code> </td><td>is adjacent to</td><td><code class="literal">numrange(1.1,2.2) -|- numrange(2.2,3.3)</code></td><td><code class="literal">t</code></td></tr><tr><td> <code class="literal">+</code> </td><td>union</td><td><code class="literal">numrange(5,15) + numrange(10,20)</code></td><td><code class="literal">[5,20)</code></td></tr><tr><td> <code class="literal">*</code> </td><td>intersection</td><td><code class="literal">int8range(5,15) * int8range(10,20)</code></td><td><code class="literal">[10,15)</code></td></tr><tr><td> <code class="literal">-</code> </td><td>difference</td><td><code class="literal">int8range(5,15) - int8range(10,20)</code></td><td><code class="literal">[5,10)</code></td></tr></tbody></table></div></div><br class="table-break" /><p>
  8. The simple comparison operators <code class="literal">&lt;</code>,
  9. <code class="literal">&gt;</code>, <code class="literal">&lt;=</code>, and
  10. <code class="literal">&gt;=</code> compare the lower bounds first, and only if those
  11. are equal, compare the upper bounds. These comparisons are not usually
  12. very useful for ranges, but are provided to allow B-tree indexes to be
  13. constructed on ranges.
  14. </p><p>
  15. The left-of/right-of/adjacent operators always return false when an empty
  16. range is involved; that is, an empty range is not considered to be either
  17. before or after any other range.
  18. </p><p>
  19. The union and difference operators will fail if the resulting range would
  20. need to contain two disjoint sub-ranges, as such a range cannot be
  21. represented.
  22. </p><p>
  23. <a class="xref" href="functions-range.html#RANGE-FUNCTIONS-TABLE" title="Table 9.54. Range Functions">Table 9.54</a> shows the functions
  24. available for use with range types.
  25. </p><a id="id-1.5.8.24.9" class="indexterm"></a><a id="id-1.5.8.24.10" class="indexterm"></a><a id="id-1.5.8.24.11" class="indexterm"></a><a id="id-1.5.8.24.12" class="indexterm"></a><a id="id-1.5.8.24.13" class="indexterm"></a><a id="id-1.5.8.24.14" class="indexterm"></a><a id="id-1.5.8.24.15" class="indexterm"></a><div class="table" id="RANGE-FUNCTIONS-TABLE"><p class="title"><strong>Table 9.54. Range Functions</strong></p><div class="table-contents"><table class="table" summary="Range Functions" border="1"><colgroup><col /><col /><col /><col /><col /></colgroup><thead><tr><th>Function</th><th>Return Type</th><th>Description</th><th>Example</th><th>Result</th></tr></thead><tbody><tr><td>
  26. <code class="literal">
  27. <code class="function">lower</code>(<code class="type">anyrange</code>)
  28. </code>
  29. </td><td>range's element type</td><td>lower bound of range</td><td><code class="literal">lower(numrange(1.1,2.2))</code></td><td><code class="literal">1.1</code></td></tr><tr><td>
  30. <code class="literal">
  31. <code class="function">upper</code>(<code class="type">anyrange</code>)
  32. </code>
  33. </td><td>range's element type</td><td>upper bound of range</td><td><code class="literal">upper(numrange(1.1,2.2))</code></td><td><code class="literal">2.2</code></td></tr><tr><td>
  34. <code class="literal">
  35. <code class="function">isempty</code>(<code class="type">anyrange</code>)
  36. </code>
  37. </td><td><code class="type">boolean</code></td><td>is the range empty?</td><td><code class="literal">isempty(numrange(1.1,2.2))</code></td><td><code class="literal">false</code></td></tr><tr><td>
  38. <code class="literal">
  39. <code class="function">lower_inc</code>(<code class="type">anyrange</code>)
  40. </code>
  41. </td><td><code class="type">boolean</code></td><td>is the lower bound inclusive?</td><td><code class="literal">lower_inc(numrange(1.1,2.2))</code></td><td><code class="literal">true</code></td></tr><tr><td>
  42. <code class="literal">
  43. <code class="function">upper_inc</code>(<code class="type">anyrange</code>)
  44. </code>
  45. </td><td><code class="type">boolean</code></td><td>is the upper bound inclusive?</td><td><code class="literal">upper_inc(numrange(1.1,2.2))</code></td><td><code class="literal">false</code></td></tr><tr><td>
  46. <code class="literal">
  47. <code class="function">lower_inf</code>(<code class="type">anyrange</code>)
  48. </code>
  49. </td><td><code class="type">boolean</code></td><td>is the lower bound infinite?</td><td><code class="literal">lower_inf('(,)'::daterange)</code></td><td><code class="literal">true</code></td></tr><tr><td>
  50. <code class="literal">
  51. <code class="function">upper_inf</code>(<code class="type">anyrange</code>)
  52. </code>
  53. </td><td><code class="type">boolean</code></td><td>is the upper bound infinite?</td><td><code class="literal">upper_inf('(,)'::daterange)</code></td><td><code class="literal">true</code></td></tr><tr><td>
  54. <code class="literal">
  55. <code class="function">range_merge</code>(<code class="type">anyrange</code>, <code class="type">anyrange</code>)
  56. </code>
  57. </td><td><code class="type">anyrange</code></td><td>the smallest range which includes both of the given ranges</td><td><code class="literal">range_merge('[1,2)'::int4range, '[3,4)'::int4range)</code></td><td><code class="literal">[1,4)</code></td></tr></tbody></table></div></div><br class="table-break" /><p>
  58. The <code class="function">lower</code> and <code class="function">upper</code> functions return null
  59. if the range is empty or the requested bound is infinite.
  60. The <code class="function">lower_inc</code>, <code class="function">upper_inc</code>,
  61. <code class="function">lower_inf</code>, and <code class="function">upper_inf</code>
  62. functions all return false for an empty range.
  63. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="functions-array.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="functions.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="functions-aggregate.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">9.18. Array Functions and Operators </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 9.20. Aggregate Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1