RefLib

Reference library for AI

Back

postgresql_16:9.6.39.2 Syntax

PostgreSQL 16 > Appendixes > Additional Supplied Modules and Extensions > seg — a datatype for line segments or floating point intervals > Syntax

The external representation of an interval is formed using one or two floating-point numbers joined by the range operator (.. or ...). Alternatively, it can be specified as a center point plus or minus a deviation. Optional certainty indicators (<, > or ~) can be stored as well. (Certainty indicators are ignored by all the built-in operators, however.) (see seg-repr-table) gives an overview of allowed representations; (see seg-input-examples) shows some examples.

In (see seg-repr-table), *x*, *y*, and *delta* denote floating-point numbers. *x* and *y*, but not *delta*, can be preceded by a certainty indicator.

| *x* | Single value (zero-length interval) | | --- | --- | | *x* .. *y* | Interval from *x* to *y* | | *x* (+-) *delta* | Interval from *x* - *delta* to *x* + *delta* | | *x* .. | Open interval with lower bound *x* | | .. *x* | Open interval with upper bound *x* |

| 5.0 | Creates a zero-length segment (a point, if you will) | | --- | --- | | ~5.0 | Creates a zero-length segment and records ~ in the data. ~ is ignored by seg operations, but is preserved as a comment. | | <5.0 | Creates a point at 5.0. < is ignored but is preserved as a comment. | | >5.0 | Creates a point at 5.0. > is ignored but is preserved as a comment. | | 5(+-)0.3 | Creates an interval 4.7 .. 5.3. Note that the (+-) notation isn't preserved. | | 50 .. | Everything that is greater than or equal to 50 | | .. 0 | Everything that is less than or equal to 0 | | 1.5e-2 .. 2E-2 | Creates an interval 0.015 .. 0.02 | | 1 ... 2 | The same as 1...2, or 1 .. 2, or 1..2 (spaces around the range operator are ignored) |

Because the ... operator is widely used in data sources, it is allowed as an alternative spelling of the .. operator. Unfortunately, this creates a parsing ambiguity: it is not clear whether the upper bound in 0...23 is meant to be 23 or 0.23. This is resolved by requiring at least one digit before the decimal point in all numbers in seg input.

As a sanity check, seg rejects intervals with the lower bound greater than the upper, for example 5 .. 2.

Back