Working with Time in Postgres
From https://www.crunchydata.com/blog/working-with-time-in-postgres
Overlapping / Intersecting Time
What if I wanted to find all of the trains that were running at a specific time or now. You can use the OVERLAP operator with the INTERVAL.
| |
Time Range Types
Postgres also support working with time ranges that include both a single range and even multiple ranges. Single ranges of the timestamptz is called tstzrange and one for multiple ranges would be tstzmultirange.
For example, if we wanted to create a table in our train database that has some peak travel fares, we could do:
| |
And now to query something with the mult-timezone range, Postgres has a special
operator for this, @>.
Let’s see if travel today is during peak time.
| |
Indexing Time Columns
Timestamps column indexes work well with the traditional B-tree index as well as BRIN. In general if you have tons of data entered sequentially a BRIN index is probably recommended.
| |
#Elizabeth Christensen #Postgresql #Overlaps #Brin_index #Tstzmultirange #B-Tree