Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Multirange types in PostgreSQL 14

One of the features we are most excited about in recently released Postgresql 14 is the introduction of Multirange Types. In a nutshell Multirange types are sets of non-overlapping ranges. Unlike array of ranges, they prevent overlaps and thus allow you to effectively model ranges with gaps.

One of the use cases we have for them is modeling time. For example if you wanted to keep track of the cumulative periods and how many days someone is in a hospital, you could store this as a datemultirange type.

There are quite a few operators and functions available in PostgreSQL 14, but some glaring ones we'd need include aggregates such as a union aggregate. That currently doesn't exist. There are however your standard operators like + (union two ranges) and * for intersection, and - for difference as well as your common containment boolean operators.

Continue reading "Multirange types in PostgreSQL 14"


This post first appeared on Postgres OnLine Journal, please read the originial post: here

Share the post

Multirange types in PostgreSQL 14

×

Subscribe to Postgres Online Journal

Get updates delivered right to your inbox!

Thank you for your subscription

×