span
pg_span · C data type for indexed document text spans, with casts, comparisons, B-tree/hash operator classes, aggregates, and accessors.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100240 | span | pg_span | 0.1.0 | TYPE | PostgreSQL | C |
Usage
Sources:
span adds a compact data type for identifying a text interval inside a document. A value has the form document:begin-end, such as article-42:10-25, and can be stored, compared, grouped, and indexed.
Core Workflow
The default B-tree operator class supports =, <>, <, <=, >, and >=. A hash operator class supports equality and hash aggregation. The extension also defines min(span) and max(span) aggregates.
Constructors and Accessors
span(text)converts validated text tospan;text(span)converts back.is_span(text)checks whether text has a valid document and ordered offsets.get_span_doc(span)returns the document identifier.get_span_begin(span)andget_span_end(span)return integer offsets.
Caveats
This type models an identifier plus two integer offsets; it does not provide overlap, containment, union, or range-index operators. Ordering is useful for deterministic sorting and B-tree lookup, not interval-search semantics. Invalid forms, missing endpoints, and a begin value greater than the end are rejected. Confirm whether application offsets are bytes, characters, or another unit and keep that convention external to the type. Version 0.1.0 is old and fixed-length, so validate document-identifier length and PostgreSQL-version compatibility before migration. No preload or restart is required.