Live data from Hacker News

Looking Forward to Postgres 19: It's About Time

pgedge.com

31–40 of 44 posts

Re: Looking Forward to Postgres 19: It's About Time

#31
post #25

This is something that is incredibly useful. I built a system like this a while back that also adds versioning to each time period. The use case is this: let’s say you are tracking your state’s sales tax rate. You do not control this and data entry is manual so it is error prone. The rate is updated typically annually but sometimes more frequently. Let’s say for 2026 you have it at 7.25% and you entered that into the…

Yeah, I think folks that under appreciate this new functionality look at the approaches that existed and say "That works, we could just sorta, wrap that in a function" but when you start getting into useful and entangled data the overhead of implementing proper bounds checking on ranges when you're more focused on the preservation of the linkages to existing data - it gets complicated quickly. This feature doesn't ma…

Exactly. This is non-trivial and the API for something like this is unusual in how you work with this data.

My hope is that Postgres making this kind of thing a first class citizen feature will mean that ORMs and other tooling incorporate it in a standard way so that developers can internalize using it. I am sure it will take time but this is a big step. Doing all this has been possible but having standardized tooling and frameworks would be nice.

Another alternative I have used is basically having a current state table and a migrations table that get applied at a specific time. The migrations table act as both a history and a set of scheduled updates. The trick is that you have to apply the migrations and so you don’t have perfect atomic changes without some sort of locking system and timing might be off. But it is a decent system that also works.

Re: Looking Forward to Postgres 19: It's About Time

#33

Some kind of versioning is extremely important for certain use cases. And having it a core DB feature makes it easier to show that you implement that checkbox. One thing I'm wondering about is the performance of temporal tables for the common case, when you only query current rows. When you manually version tables, one strategy is to have a second table that contains archived versions. So your main table only has the…

For application time, everything lives in one table (although you could partition it). The biggest performance hit, I suspect, will come from GiST indexes instead of B-Trees. Some general GiST improvements are on my TODO list, and I learned at PGConf.dev that several other people already have patches for cool perf-related GiST enhancements.

For system time, a separate history table is a common implementation, sometimes also with partitioning. Here is what other vendors are doing: https://illuminatedcomputing.com/posts/2019/08/sql2011-surve...

Re: Looking Forward to Postgres 19: It's About Time

#34
post #26

Ooh fantastic. I’ve been using date ranges plus GIST indexes for like a decade to do this. It’s really nice. But the lack of foreign keys can be painful. I’ve resorted to stored procedures for crates and updates to ensure everything is done right and enforced. This is WAY easier.

The FK piece is what I'm most excited about. PRIMARY KEY WITHOUT OVERLAPS plus FOREIGN KEY ... PERIOD means a child row's range is enforced to stay inside an actual parent version, no triggers or sprocs needed. Not free (GiST lookups add up on hot tables), but for slowly changing dimensions it kills a whole class of footgun.

Re: Looking Forward to Postgres 19: It's About Time

#35

Hey I worked on this! Thank you to everyone here saying they are excited about it. I often hear doubts that anyone wants this. Perhaps that's why vendors have been so slow to add it. And thank you 'bonesmoses for writing about it! We are still missing system time, but if no one else wants to work on it, I hope to tackle that soon. I have a lot of other ideas for improvement beyond SQL:2011, too. Here is a talk I gave…

> I often hear doubts that anyone wants this.

This was actually a key feature that was greatly desired by a large organization's HR function when they were working to setup a consolidated enterprise data warehouse a decade back.

It would have made it much easier for retention specialists to be able to do things like answer how much a missed retention bonus should have been once the paperwork had been fixed up.

Likewise for the same organization's board for correction of records, and in general any offices that have to make sense of what the world was like for the computer-based records years ago, and how that would change if certain data would have been different years ago.

Re: Looking Forward to Postgres 19: It's About Time

#39

Hey I worked on this! Thank you to everyone here saying they are excited about it. I often hear doubts that anyone wants this. Perhaps that's why vendors have been so slow to add it. And thank you 'bonesmoses for writing about it! We are still missing system time, but if no one else wants to work on it, I hope to tackle that soon. I have a lot of other ideas for improvement beyond SQL:2011, too. Here is a talk I gave…

How tied is the implementation to time specifically?

Can it apply to other types (eg geometries) which can be subdivided?

Re: Looking Forward to Postgres 19: It's About Time

#40

Hey I worked on this! Thank you to everyone here saying they are excited about it. I often hear doubts that anyone wants this. Perhaps that's why vendors have been so slow to add it. And thank you 'bonesmoses for writing about it! We are still missing system time, but if no one else wants to work on it, I hope to tackle that soon. I have a lot of other ideas for improvement beyond SQL:2011, too. Here is a talk I gave…

There’s definitely interest in this in finance domains. I’ve done DATERANGE and GiST exclude constraints based solutions for a symbology database for example, where any given ticker might represent different securities at different times without overlap, and relying on functions to keep the dateranges in sync when updating a row.

So basically what WHITOUT OVERLAPS and FOR PORTION OF do.

The system time is also interesting in the context of financial data and backtesting, as companies might republish a statement with corrections, and it would help tracking why the system made a decision at a given time.

This bridges the gap to something like xtdb.

Post reply on HN