バージョンごとのドキュメント一覧

F.39. seg — 線分または浮動小数点区間のためのデータ型 #

<title>seg &mdash; a datatype for line segments or floating point intervals</title>

This module implements a data type <type>seg</type> for representing line segments, or floating point intervals. <type>seg</type> can represent uncertainty in the interval endpoints, making it especially useful for representing laboratory measurements. 本モジュールは線分、浮動小数点区間を表現するsegデータ型を実装します。 segは区間の終端内の不確定性を表すことができ、特に実験計測の表現に有用です。

This module is considered <quote>trusted</quote>, that is, it can be installed by non-superusers who have <literal>CREATE</literal> privilege on the current database. このモジュールはtrustedと見なされます。つまり、現在のデータベースに対してCREATE権限を持つ非スーパーユーザがインストールできます。

F.39.1. 原理 #

<title>Rationale</title>

The geometry of measurements is usually more complex than that of a point in a numeric continuum. A measurement is usually a segment of that continuum with somewhat fuzzy limits. The measurements come out as intervals because of uncertainty and randomness, as well as because the value being measured may naturally be an interval indicating some condition, such as the temperature range of stability of a protein. 計測の幾何は数値の連続における点より通常より複雑です。 計測は通常、多少あいまいな制限を持つ連続の部分となります。 不確実性と不規則性のため、さらに、タンパク質を安定させる温度範囲など計測される値は本質的に何らかの状態を示す区間となる可能性があるため、計測は区間として現れます。

Using just common sense, it appears more convenient to store such data as intervals, rather than pairs of numbers. In practice, it even turns out more efficient in most applications. 一般的な見方を使うと、こうしたデータは値の組合せではなく区間としてデータを格納する方が便利なようです。 実際、ほとんどのアプリケーションでより効率的であると判明してさえいます。

Further along the line of common sense, the fuzziness of the limits suggests that the use of traditional numeric data types leads to a certain loss of information. Consider this: your instrument reads 6.50, and you input this reading into the database. What do you get when you fetch it? Watch: 一般的な見方をさらに進めると、制限の曖昧さは、伝統的な数値データ型を使用することで情報がある程度損失してしまうことを暗示しています。 これを考えてみましょう。 計測機器で6.50と読み取り、読み取ったデータをデータベースに格納します。 それを取り出す時にどうなるでしょう。 見てみましょう。

test=> select 6.50 :: float8 as "pH";
 pH
---
6.5
(1 row)

In the world of measurements, 6.50 is not the same as 6.5. It may sometimes be critically different. The experimenters usually write down (and publish) the digits they trust. 6.50 is actually a fuzzy interval contained within a bigger and even fuzzier interval, 6.5, with their center points being (probably) the only common feature they share. We definitely do not want such different data items to appear the same. 計測という世界では6.50は6.5と同じではありません。 時としてこれが致命的な違いになる場合があります。 実験者は信頼する桁を書き出し(公開し)ます。 6.50は実際には、6.5というより大きくよりあいまいな区間に含まれるあいまいな区間です。 2つに共通するものは(おそらく)その中央の値だけでしょう。 私達は厳密にこうした異なるデータ項目が同じものとして現れることを好みません。

Conclusion? It is nice to have a special data type that can record the limits of an interval with arbitrarily variable precision. Variable in the sense that each data element records its own precision. まとめ? 任意の可変精度を持つ区間の制限を記録できる特別なデータ型を持つことは素晴らしいことでしょう。 各データ要素が独自の精度を記録するという意味での可変です。

Check this out: 以下を見てください。

test=> select '6.25 .. 6.50'::seg as "pH";
          pH
------------
6.25 .. 6.50
(1 row)

F.39.2. 構文 #

<title>Syntax</title>

The external representation of an interval is formed using one or two floating-point numbers joined by the range operator (<literal>..</literal> or <literal>...</literal>). Alternatively, it can be specified as a center point plus or minus a deviation. Optional certainty indicators (<literal>&lt;</literal>, <literal>&gt;</literal> or <literal>~</literal>) can be stored as well. (Certainty indicators are ignored by all the built-in operators, however.) <xref linkend="seg-repr-table"/> gives an overview of allowed representations; <xref linkend="seg-input-examples"/> shows some examples. 区間の外部表現は、1つまたは2つの浮動小数点値を範囲演算子(..または...)で結び付けた形になります。 他にも、中央値と正負の偏差として指定することも可能です。 省略可能な確実性指示子(<>~)を格納することもできます。 (しかし、確実性指示子はすべての組み込みの演算子で無視されます。) 表 F.28に許される表現についての概要を、表 F.29にいくつか例を示します。

In <xref linkend="seg-repr-table"/>, <replaceable>x</replaceable>, <replaceable>y</replaceable>, and <replaceable>delta</replaceable> denote floating-point numbers. <replaceable>x</replaceable> and <replaceable>y</replaceable>, but not <replaceable>delta</replaceable>, can be preceded by a certainty indicator. 表 F.28では、xydeltaは浮動小数点数値を表します。 delta以外のxyの前に確実性指示子を付与することができます。

表F.28 seg外部表現

<title><type>seg</type> External Representations</title>
x単一値(幅0の区間)
x .. yxからyまでの区間
x (+-) deltax - deltaからx + deltaまでの区間
x ..下限値xを持つ閉じていない区間
.. x上限値xを持つ閉じていない区間

表F.29 有効なSEG入力の例

<title>Examples of Valid <type>seg</type> Input</title>
5.0 Creates a zero-length segment (a point, if you will) 幅0のセグメントを作成します(こうすると点になります)。
~5.0 Creates a zero-length segment and records <literal>~</literal> in the data. <literal>~</literal> is ignored by <type>seg</type> operations, but is preserved as a comment. 幅0のセグメントを作成し、データ内に~を記録します。 ~seg型の演算では無視されますが、コメントとして保持されます。
<5.0 Creates a point at 5.0. <literal>&lt;</literal> is ignored but is preserved as a comment. 5.0という点を作成します。 <は無視されますが、コメントとして保持されます。
>5.0 Creates a point at 5.0. <literal>&gt;</literal> is ignored but is preserved as a comment. 5.0という点を作成します。 >は無視されますが、コメントとして保持されます。
5(+-)0.3 Creates an interval <literal>4.7 .. 5.3</literal>. Note that the <literal>(+-)</literal> notation isn't preserved. 4.7 .. 5.3という区間を作成します。 (+-)という記述は保持されないことに注意してください。
50 .. 50以上のすべて
.. 00以下のすべて
1.5e-2 .. 2E-2 0.015 .. 0.02という区間を作成します
1 ... 2 The same as <literal>1...2</literal>, or <literal>1 .. 2</literal>, or <literal>1..2</literal> (spaces around the range operator are ignored) 1...21 .. 21..2と同じです(範囲演算子前後の空白は無視されます)。

Because the <literal>...</literal> operator is widely used in data sources, it is allowed as an alternative spelling of the <literal>..</literal> operator. Unfortunately, this creates a parsing ambiguity: it is not clear whether the upper bound in <literal>0...23</literal> is meant to be <literal>23</literal> or <literal>0.23</literal>. This is resolved by requiring at least one digit before the decimal point in all numbers in <type>seg</type> input. データソースで...演算子が広く使用されるため、..演算子の代わりの綴りとして許可されています。 残念なことにこれにより解析上の曖昧性が生じました。 0...23の上限が23なのか0.23なのかが明確ではありません。 これは、segの入力において、少なくとも1つの桁を数値内の小数点の前に書くことを要求することで解決されます。

As a sanity check, <type>seg</type> rejects intervals with the lower bound greater than the upper, for example <literal>5 .. 2</literal>. 健全性検査としてsegは、5 .. 2のような、下限値が上限値より大きな区間を拒絶します。

F.39.3. 精度 #

<title>Precision</title>

<type>seg</type> values are stored internally as pairs of 32-bit floating point numbers. This means that numbers with more than 7 significant digits will be truncated. 内部的にseg値には32ビット浮動小数点数値の組合せが格納されます。 これは7桁以上の有効桁を持つ数値が切り詰められることを意味します。

Numbers with 7 or fewer significant digits retain their original precision. That is, if your query returns 0.00, you will be sure that the trailing zeroes are not the artifacts of formatting: they reflect the precision of the original data. The number of leading zeroes does not affect precision: the value 0.0067 is considered to have just 2 significant digits. 有効桁が正確に7桁、または7桁未満の数値は元の精度が保たれます。 つまり、問い合わせが0.00を返す場合、後ろに続く0は書式付けのための見かけのものではないことが確実です。 これは元のデータの精度を反映します。 前にある0の数は精度には影響しません。 0.0067は2有効桁のみを持つものと考えられます。

F.39.4. 使用方法 #

<title>Usage</title>

The <filename>seg</filename> module includes a GiST index operator class for <type>seg</type> values. The operators supported by the GiST operator class are shown in <xref linkend="seg-gist-operators"/>. segモジュールにはseg値用のGiSTインデックス演算子クラスが含まれます。 GiST演算子クラスでサポートされる演算子を表 F.30に示します。

表F.30 Seg GiST演算子

<title>Seg GiST Operators</title>

Operator 演算子

Description 説明

seg << segboolean

Is the first <type>seg</type> entirely to the left of the second? [a, b] &lt;&lt; [c, d] is true if b &lt; c. 1番目のsegが完全に2番目の左側に存在するか。 b < cならば[a, b] << [c, d]は真です。

seg >> segboolean

Is the first <type>seg</type> entirely to the right of the second? [a, b] &gt;&gt; [c, d] is true if a &gt; d. 1番目のsegが完全に2番目の右側に存在するか。 a > dならば[a, b] >> [c, d]は真です。

seg &< segboolean

Does the first <type>seg</type> not extend to the right of the second? [a, b] &amp;&lt; [c, d] is true if b &lt;= d. 1番目のsegは2番目の右側にはみ出さないか。 b <= dならば[a, b] &< [c, d]は真です。

seg &> segboolean

Does the first <type>seg</type> not extend to the left of the second? [a, b] &amp;&gt; [c, d] is true if a &gt;= c. 1番目のsegは2番目の左側にはみ出さないか。 a >= cならば[a, b] &> [c, d]は真です。

seg = segboolean

Are the two <type>seg</type>s equal? 2つのsegは等しいか。

seg && segboolean

Do the two <type>seg</type>s overlap? 2つのsegは重なるか。

seg @> segboolean

Does the first <type>seg</type> contain the second? 1番目のsegは2番目を包含するか。

seg <@ segboolean

Is the first <type>seg</type> contained in the second? 1番目のsegは2番目に包含されるか。


In addition to the above operators, the usual comparison operators shown in <xref linkend="functions-comparison-op-table"/> are available for type <type>seg</type>. These operators first compare (a) to (c), and if these are equal, compare (b) to (d). That results in reasonably good sorting in most cases, which is useful if you want to use ORDER BY with this type. 上記の演算子に加えて、seg型では表 9.1にある通常の比較演算子が利用可能です。 これらの演算子はまず(a)と(c)を比べ、等しければ(b)と(d)を比べます。 論理的にはほとんどの場合優れたソート処理と思えます。 こうした型をORDER BYで使用したい場合に有用です。

F.39.5. 注釈 #

<title>Notes</title>

For examples of usage, see the regression test <filename>sql/seg.sql</filename>. 使用方法の例はリグレッションテストのsql/seg.sqlを参照してください。

The mechanism that converts <literal>(+-)</literal> to regular ranges isn't completely accurate in determining the number of significant digits for the boundaries. For example, it adds an extra digit to the lower boundary if the resulting interval includes a power of ten: (+-)を通常の範囲に変換する機構は、境界で有効な桁数を決定するという点で完全に正確ではありません。 例えば以下のように、結果の区間に10の冪乗が含まれる場合、下限値に余計な桁を追加します。

postgres=> select '10(+-)1'::seg as seg;
      seg
---------

9.0 .. 11             &#45;- should be: 9 .. 11

9.0 .. 11             -- 次のようになるべきです: 9 .. 11

The performance of an R-tree index can largely depend on the initial order of input values. It may be very helpful to sort the input table on the <type>seg</type> column; see the script <filename>sort-segments.pl</filename> for an example. R-treeインデックスの性能は入力値の初期の順序に大きく依存する可能性があります。 seg列で入力テーブルをソートすることは非常に役に立つでしょう。 例としてsort-segments.plスクリプトを参照してください。

F.39.6. クレジット #

<title>Credits</title>

Original author: Gene Selkov, Jr. <email>selkovjr@mcs.anl.gov</email>, Mathematics and Computer Science Division, Argonne National Laboratory. 原作者:Gene Selkov, Jr. , Mathematics and Computer Science Division, Argonne National Laboratory.

My thanks are primarily to Prof. Joe Hellerstein (<ulink url="https://dsf.berkeley.edu/jmh/"></ulink>) for elucidating the gist of the GiST (<ulink url="http://gist.cs.berkeley.edu/"></ulink>). I am also grateful to all Postgres developers, present and past, for enabling myself to create my own world and live undisturbed in it. And I would like to acknowledge my gratitude to Argonne Lab and to the U.S. Department of Energy for the years of faithful support of my database research. GiST (http://gist.cs.berkeley.edu/)の要旨(gist)を説明していただいたJoe Hellerstein博士(https://dsf.berkeley.edu/jmh/)に感謝します。 また、自分の世界を作成できるようにし、静かに生活できるようにしてもらった、過去から現在までのすべてのPostgres開発者に感謝します。 データベース研究を長年誠実にサポートしてくれたArgonne LabとU.S. Department of Energyにも感謝します。