Data Types and Storage
Seg
Line segment and floating-point interval data type for PostgreSQL
The seg
extension provides support for representing line segments or floating-point intervals in PostgreSQL.
This type represents both ranges of values and also measurements with uncertainty, randomness or tolerances.
Your Nile database arrives with the seg extension already enabled.
Overview
The seg extension adds a new data type seg
that can represent:
- Line segments on a number line
- Floating-point intervals
- Exact or inexact bounds
- Infinite bounds using
< x
or> x
notation
Data Type Format
The seg
data type accepts several input formats:
Format | Example | Description |
---|---|---|
x | 5.0 | Single value, a point |
x .. y | 1.0 .. 2.0 | Interval from x to y |
x .. | 1.0 .. | Everything greater than x |
.. y | .. 2.0 | Everything less than y |
<x | <5.0 | A point at X. < is preserved as a comment |
>x | >5.0 | A point at X. > is preserved as a comment |
~x | ~5.0 | A point at X. ~ is preserved as a comment |
x(+-)d | 5.0(+-)0.1 | Interval from x-d to x+d |
Examples
Creating Segments
Comparison Operations
Working with Measurement Ranges
Use Cases
The seg extension can be used with any type of data that can be represented as a floating-point interval. But it is most useful for recording laboratory measurements with uncertainty or tolerances.
Performance Optimization
For better query performance with seg data:
- Create GiST indexes on seg columns:
- Common operators that can use the GiST index:
<<
(strictly left of)>>
(strictly right of)&<
(does not extend right of)&>
(does not extend left of)&&
(overlaps)@>
(contains)<@
(contained in)