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.

176 line
16KB

  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>F.34. seg</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="postgres-fdw.html" title="F.33. postgres_fdw" /><link rel="next" href="sepgsql.html" title="F.35. sepgsql" /></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">F.34. seg</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="postgres-fdw.html" title="F.33. postgres_fdw">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules</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="sepgsql.html" title="F.35. sepgsql">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="SEG"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.34. seg</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="seg.html#id-1.11.7.43.4">F.34.1. Rationale</a></span></dt><dt><span class="sect2"><a href="seg.html#id-1.11.7.43.5">F.34.2. Syntax</a></span></dt><dt><span class="sect2"><a href="seg.html#id-1.11.7.43.6">F.34.3. Precision</a></span></dt><dt><span class="sect2"><a href="seg.html#id-1.11.7.43.7">F.34.4. Usage</a></span></dt><dt><span class="sect2"><a href="seg.html#id-1.11.7.43.8">F.34.5. Notes</a></span></dt><dt><span class="sect2"><a href="seg.html#id-1.11.7.43.9">F.34.6. Credits</a></span></dt></dl></div><a id="id-1.11.7.43.2" class="indexterm"></a><p>
  3. This module implements a data type <code class="type">seg</code> for
  4. representing line segments, or floating point intervals.
  5. <code class="type">seg</code> can represent uncertainty in the interval endpoints,
  6. making it especially useful for representing laboratory measurements.
  7. </p><div class="sect2" id="id-1.11.7.43.4"><div class="titlepage"><div><div><h3 class="title">F.34.1. Rationale</h3></div></div></div><p>
  8. The geometry of measurements is usually more complex than that of a
  9. point in a numeric continuum. A measurement is usually a segment of
  10. that continuum with somewhat fuzzy limits. The measurements come out
  11. as intervals because of uncertainty and randomness, as well as because
  12. the value being measured may naturally be an interval indicating some
  13. condition, such as the temperature range of stability of a protein.
  14. </p><p>
  15. Using just common sense, it appears more convenient to store such data
  16. as intervals, rather than pairs of numbers. In practice, it even turns
  17. out more efficient in most applications.
  18. </p><p>
  19. Further along the line of common sense, the fuzziness of the limits
  20. suggests that the use of traditional numeric data types leads to a
  21. certain loss of information. Consider this: your instrument reads
  22. 6.50, and you input this reading into the database. What do you get
  23. when you fetch it? Watch:
  24. </p><pre class="screen">
  25. test=&gt; select 6.50 :: float8 as "pH";
  26. pH
  27. ---
  28. 6.5
  29. (1 row)
  30. </pre><p>
  31. In the world of measurements, 6.50 is not the same as 6.5. It may
  32. sometimes be critically different. The experimenters usually write
  33. down (and publish) the digits they trust. 6.50 is actually a fuzzy
  34. interval contained within a bigger and even fuzzier interval, 6.5,
  35. with their center points being (probably) the only common feature they
  36. share. We definitely do not want such different data items to appear the
  37. same.
  38. </p><p>
  39. Conclusion? It is nice to have a special data type that can record the
  40. limits of an interval with arbitrarily variable precision. Variable in
  41. the sense that each data element records its own precision.
  42. </p><p>
  43. Check this out:
  44. </p><pre class="screen">
  45. test=&gt; select '6.25 .. 6.50'::seg as "pH";
  46. pH
  47. ------------
  48. 6.25 .. 6.50
  49. (1 row)
  50. </pre><p>
  51. </p></div><div class="sect2" id="id-1.11.7.43.5"><div class="titlepage"><div><div><h3 class="title">F.34.2. Syntax</h3></div></div></div><p>
  52. The external representation of an interval is formed using one or two
  53. floating-point numbers joined by the range operator (<code class="literal">..</code>
  54. or <code class="literal">...</code>). Alternatively, it can be specified as a
  55. center point plus or minus a deviation.
  56. Optional certainty indicators (<code class="literal">&lt;</code>,
  57. <code class="literal">&gt;</code> or <code class="literal">~</code>) can be stored as well.
  58. (Certainty indicators are ignored by all the built-in operators, however.)
  59. <a class="xref" href="seg.html#SEG-REPR-TABLE" title="Table F.26. seg External Representations">Table F.26</a> gives an overview of allowed
  60. representations; <a class="xref" href="seg.html#SEG-INPUT-EXAMPLES" title="Table F.27. Examples of Valid seg Input">Table F.27</a> shows some
  61. examples.
  62. </p><p>
  63. In <a class="xref" href="seg.html#SEG-REPR-TABLE" title="Table F.26. seg External Representations">Table F.26</a>, <em class="replaceable"><code>x</code></em>, <em class="replaceable"><code>y</code></em>, and
  64. <em class="replaceable"><code>delta</code></em> denote
  65. floating-point numbers. <em class="replaceable"><code>x</code></em> and <em class="replaceable"><code>y</code></em>, but
  66. not <em class="replaceable"><code>delta</code></em>, can be preceded by a certainty indicator.
  67. </p><div class="table" id="SEG-REPR-TABLE"><p class="title"><strong>Table F.26. <code class="type">seg</code> External Representations</strong></p><div class="table-contents"><table class="table" summary="seg External Representations" border="1"><colgroup><col /><col /></colgroup><tbody><tr><td><code class="literal"><em class="replaceable"><code>x</code></em></code></td><td>Single value (zero-length interval)
  68. </td></tr><tr><td><code class="literal"><em class="replaceable"><code>x</code></em> .. <em class="replaceable"><code>y</code></em></code></td><td>Interval from <em class="replaceable"><code>x</code></em> to <em class="replaceable"><code>y</code></em>
  69. </td></tr><tr><td><code class="literal"><em class="replaceable"><code>x</code></em> (+-) <em class="replaceable"><code>delta</code></em></code></td><td>Interval from <em class="replaceable"><code>x</code></em> - <em class="replaceable"><code>delta</code></em> to
  70. <em class="replaceable"><code>x</code></em> + <em class="replaceable"><code>delta</code></em>
  71. </td></tr><tr><td><code class="literal"><em class="replaceable"><code>x</code></em> ..</code></td><td>Open interval with lower bound <em class="replaceable"><code>x</code></em>
  72. </td></tr><tr><td><code class="literal">.. <em class="replaceable"><code>x</code></em></code></td><td>Open interval with upper bound <em class="replaceable"><code>x</code></em>
  73. </td></tr></tbody></table></div></div><br class="table-break" /><div class="table" id="SEG-INPUT-EXAMPLES"><p class="title"><strong>Table F.27. Examples of Valid <code class="type">seg</code> Input</strong></p><div class="table-contents"><table class="table" summary="Examples of Valid seg Input" border="1"><colgroup><col /><col /></colgroup><tbody><tr><td><code class="literal">5.0</code></td><td>
  74. Creates a zero-length segment (a point, if you will)
  75. </td></tr><tr><td><code class="literal">~5.0</code></td><td>
  76. Creates a zero-length segment and records
  77. <code class="literal">~</code> in the data. <code class="literal">~</code> is ignored
  78. by <code class="type">seg</code> operations, but
  79. is preserved as a comment.
  80. </td></tr><tr><td><code class="literal">&lt;5.0</code></td><td>
  81. Creates a point at 5.0. <code class="literal">&lt;</code> is ignored but
  82. is preserved as a comment.
  83. </td></tr><tr><td><code class="literal">&gt;5.0</code></td><td>
  84. Creates a point at 5.0. <code class="literal">&gt;</code> is ignored but
  85. is preserved as a comment.
  86. </td></tr><tr><td><code class="literal">5(+-)0.3</code></td><td>
  87. Creates an interval <code class="literal">4.7 .. 5.3</code>.
  88. Note that the <code class="literal">(+-)</code> notation isn't preserved.
  89. </td></tr><tr><td><code class="literal">50 .. </code></td><td>Everything that is greater than or equal to 50</td></tr><tr><td><code class="literal">.. 0</code></td><td>Everything that is less than or equal to 0</td></tr><tr><td><code class="literal">1.5e-2 .. 2E-2 </code></td><td>Creates an interval <code class="literal">0.015 .. 0.02</code></td></tr><tr><td><code class="literal">1 ... 2</code></td><td>
  90. The same as <code class="literal">1...2</code>, or <code class="literal">1 .. 2</code>,
  91. or <code class="literal">1..2</code>
  92. (spaces around the range operator are ignored)
  93. </td></tr></tbody></table></div></div><br class="table-break" /><p>
  94. Because <code class="literal">...</code> is widely used in data sources, it is allowed
  95. as an alternative spelling of <code class="literal">..</code>. Unfortunately, this
  96. creates a parsing ambiguity: it is not clear whether the upper bound
  97. in <code class="literal">0...23</code> is meant to be <code class="literal">23</code> or <code class="literal">0.23</code>.
  98. This is resolved by requiring at least one digit before the decimal
  99. point in all numbers in <code class="type">seg</code> input.
  100. </p><p>
  101. As a sanity check, <code class="type">seg</code> rejects intervals with the lower bound
  102. greater than the upper, for example <code class="literal">5 .. 2</code>.
  103. </p></div><div class="sect2" id="id-1.11.7.43.6"><div class="titlepage"><div><div><h3 class="title">F.34.3. Precision</h3></div></div></div><p>
  104. <code class="type">seg</code> values are stored internally as pairs of 32-bit floating point
  105. numbers. This means that numbers with more than 7 significant digits
  106. will be truncated.
  107. </p><p>
  108. Numbers with 7 or fewer significant digits retain their
  109. original precision. That is, if your query returns 0.00, you will be
  110. sure that the trailing zeroes are not the artifacts of formatting: they
  111. reflect the precision of the original data. The number of leading
  112. zeroes does not affect precision: the value 0.0067 is considered to
  113. have just 2 significant digits.
  114. </p></div><div class="sect2" id="id-1.11.7.43.7"><div class="titlepage"><div><div><h3 class="title">F.34.4. Usage</h3></div></div></div><p>
  115. The <code class="filename">seg</code> module includes a GiST index operator class for
  116. <code class="type">seg</code> values.
  117. The operators supported by the GiST operator class are shown in <a class="xref" href="seg.html#SEG-GIST-OPERATORS" title="Table F.28. Seg GiST Operators">Table F.28</a>.
  118. </p><div class="table" id="SEG-GIST-OPERATORS"><p class="title"><strong>Table F.28. Seg GiST Operators</strong></p><div class="table-contents"><table class="table" summary="Seg GiST Operators" border="1"><colgroup><col /><col /></colgroup><thead><tr><th>Operator</th><th>Description</th></tr></thead><tbody><tr><td><code class="literal">[a, b] &lt;&lt; [c, d]</code></td><td>[a, b] is entirely to the left of [c, d]. That is, [a,
  119. b] &lt;&lt; [c, d] is true if b &lt; c and false otherwise.</td></tr><tr><td><code class="literal">[a, b] &gt;&gt; [c, d]</code></td><td>[a, b] is entirely to the right of [c, d]. That is, [a,
  120. b] &gt;&gt; [c, d] is true if a &gt; d and false otherwise.</td></tr><tr><td><code class="literal">[a, b] &amp;&lt; [c, d]</code></td><td>Overlaps or is left of — This might be better read
  121. as <span class="quote">“<span class="quote">does not extend to right of</span>”</span>. It is true when
  122. b &lt;= d.</td></tr><tr><td><code class="literal">[a, b] &amp;&gt; [c, d]</code></td><td>Overlaps or is right of — This might be better read
  123. as <span class="quote">“<span class="quote">does not extend to left of</span>”</span>. It is true when
  124. a &gt;= c.</td></tr><tr><td><code class="literal">[a, b] = [c, d]</code></td><td>Same as — The segments [a, b] and [c, d] are
  125. identical, that is, a = c and b = d.</td></tr><tr><td><code class="literal">[a, b] &amp;&amp; [c, d]</code></td><td>The segments [a, b] and [c, d] overlap.</td></tr><tr><td><code class="literal">[a, b] @&gt; [c, d]</code></td><td>The segment [a, b] contains the segment [c, d], that is,
  126. a &lt;= c and b &gt;= d.</td></tr><tr><td><code class="literal">[a, b] &lt;@ [c, d]</code></td><td>The segment [a, b] is contained in [c, d], that is, a
  127. &gt;= c and b &lt;= d.</td></tr></tbody></table></div></div><br class="table-break" /><p>
  128. (Before PostgreSQL 8.2, the containment operators <code class="literal">@&gt;</code> and <code class="literal">&lt;@</code> were
  129. respectively called <code class="literal">@</code> and <code class="literal">~</code>. These names are still available, but are
  130. deprecated and will eventually be retired. Notice that the old names
  131. are reversed from the convention formerly followed by the core geometric
  132. data types!)
  133. </p><p>
  134. The standard B-tree operators are also provided, for example
  135. </p><div class="informaltable"><table class="informaltable" border="1"><colgroup><col /><col /></colgroup><thead><tr><th>Operator</th><th>Description</th></tr></thead><tbody><tr><td><code class="literal">[a, b] &lt; [c, d]</code></td><td>Less than</td></tr><tr><td><code class="literal">[a, b] &gt; [c, d]</code></td><td>Greater than</td></tr></tbody></table></div><p>
  136. These operators do not make a lot of sense for any practical
  137. purpose but sorting. These operators first compare (a) to (c),
  138. and if these are equal, compare (b) to (d). That results in
  139. reasonably good sorting in most cases, which is useful if
  140. you want to use ORDER BY with this type.
  141. </p></div><div class="sect2" id="id-1.11.7.43.8"><div class="titlepage"><div><div><h3 class="title">F.34.5. Notes</h3></div></div></div><p>
  142. For examples of usage, see the regression test <code class="filename">sql/seg.sql</code>.
  143. </p><p>
  144. The mechanism that converts <code class="literal">(+-)</code> to regular ranges
  145. isn't completely accurate in determining the number of significant digits
  146. for the boundaries. For example, it adds an extra digit to the lower
  147. boundary if the resulting interval includes a power of ten:
  148. </p><pre class="screen">
  149. postgres=&gt; select '10(+-)1'::seg as seg;
  150. seg
  151. ---------
  152. 9.0 .. 11 -- should be: 9 .. 11
  153. </pre><p>
  154. </p><p>
  155. The performance of an R-tree index can largely depend on the initial
  156. order of input values. It may be very helpful to sort the input table
  157. on the <code class="type">seg</code> column; see the script <code class="filename">sort-segments.pl</code>
  158. for an example.
  159. </p></div><div class="sect2" id="id-1.11.7.43.9"><div class="titlepage"><div><div><h3 class="title">F.34.6. Credits</h3></div></div></div><p>
  160. Original author: Gene Selkov, Jr. <code class="email">&lt;<a class="email" href="mailto:selkovjr@mcs.anl.gov">selkovjr@mcs.anl.gov</a>&gt;</code>,
  161. Mathematics and Computer Science Division, Argonne National Laboratory.
  162. </p><p>
  163. My thanks are primarily to Prof. Joe Hellerstein
  164. (<a class="ulink" href="https://dsf.berkeley.edu/jmh/" target="_top">https://dsf.berkeley.edu/jmh/</a>) for elucidating the
  165. gist of the GiST (<a class="ulink" href="http://gist.cs.berkeley.edu/" target="_top">http://gist.cs.berkeley.edu/</a>). I am
  166. also grateful to all Postgres developers, present and past, for enabling
  167. myself to create my own world and live undisturbed in it. And I would like
  168. to acknowledge my gratitude to Argonne Lab and to the U.S. Department of
  169. Energy for the years of faithful support of my database research.
  170. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="postgres-fdw.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="sepgsql.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.33. postgres_fdw </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> F.35. sepgsql</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1