Search⌘ K
AI Features

Ranges

Explore how to use PostgreSQL range types to manage date intervals efficiently within single columns. Understand exclusion constraints to prevent overlapping ranges and apply window functions to retrieve valid data. This lesson helps you handle advanced data scenarios like currency exchange rates with clear examples.

Range types

Range types are a unique feature of PostgreSQL, managing two dimensions of data in a single column and allowing advanced processing. The main example is the daterange data type, which stores as a single value a lower and an upper bound of the range. This allows PostgreSQL to implement a concurrent safe check against overlapping ranges, as we’re going to see in the next example.

As usual, read the PostgreSQL documentation chapters with the titles “Range Types” and “Range Functions and Operators” for complete information.

A use case

The International Monetary Fund publishes exchange rate archives by month for lots ...