efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

Look into supporting temporal data

Open roji opened this issue 4 years ago • 18 comments

Good end-to-end overview of the PG18 temporal features

Old/irrelevant pre-PG18 resources

  • temporal_tables extension: https://github.com/arkhipov/temporal_tables/commits/master
  • https://www.dbi-services.com/blog/temporal-tables-for-postgresql-15/
  • https://wiki.postgresql.org/images/6/64/Fosdem20150130PostgresqlTemporal.pdf
  • https://clarkdave.net/2015/02/historical-records-with-postgresql-and-temporal-tables-and-sql-2011/

roji avatar Nov 12 '21 21:11 roji

Is this still on your radar for 7.0? Temporal tables is a possible solution for something I'm working on, and frankly, I'd love to avoid needing to justify the financial and development time costs of trying to migrate from PG to SQL Server

evman182 avatar Jul 01 '22 18:07 evman182

It's unfortunately unlikely that I'll be able to do this for 7.0... One reason I'm a bit hesitant about doing this, is that it's unclear to what extent the above extension is up-to-date and the "final" temporal table support for PG; see notably this about possible movement for PG15. So it may be worth holding back on implementation until something more official makes it in.

However, it's probably possible to implement some scenarios with the temporal extension even without EF support - you may not actually need EF Core itself to know about temporal tables. Table creation can be managed with raw SQL in migrations (to add the temporal component), and as long as EF Core itself is used to query up-to-date date only, it doesn't need to be aware of the temporality. In other words, if the idea is for the application to access up-to-date data and use the temporal table as a manually-accessed audit or log, then things should be possible without any EF Core support.

roji avatar Jul 02 '22 07:07 roji

I was reading the email thread about the PG patch a few days ago. Unfortunately it doesn't seem to be anywhere near getting merged.

Unfortunately the use case for which I'm looking to use temporal tables requires accessing them as part of the regular functions of the application.

evman182 avatar Jul 03 '22 19:07 evman182

@evman182 I understand, and I'm sorry there aren't better news on this at the moment. You should hopefully be able to get by with raw SQL in EF Core for the temporal syntax - remember you can use that for the basic temporal query and then compose other LINQ query operators on top.

roji avatar Jul 03 '22 20:07 roji

@roji Hi, there is an new Version of the extension available https://github.com/arkhipov/temporal_tables

ps-nk avatar Apr 20 '23 15:04 ps-nk

@nk-cmd thanks. It's good to know that there's progress there, but I'm still reluctant to do the substantial work needed to support temporal tables on an unofficial extension etc.

roji avatar Apr 20 '23 15:04 roji

Is there any issue to track for this becoming an official feature of postgre?

domagojmedo avatar Apr 20 '23 15:04 domagojmedo

@domagojmedo are you referring to the temporal_tables extension linked to above? If so, I have no idea (and that isn't really related to this repo in any way).

roji avatar Apr 20 '23 15:04 roji

Yes, I understand it's not related to this repo. I was just following up on your comment that you won't do any work for unofficial extension (which is completely understandable). I was just wondering if you maybe know if this feature is even in consideration to be implemented as official postgre feature

domagojmedo avatar Apr 20 '23 15:04 domagojmedo

This hasn't seen an update in a few years, what's the update on this?

@BenjamynWilliams-IconGroup the situation hasn't really changed on the PG side - AFAIK there's no official temporal tables feature; see the comments above, they're all still valid.

roji avatar Jun 16 '23 04:06 roji

This hasn't seen an update in a few years, what's the update on this?

maybe you can use interceptors and write your own layer above ef itself and spin a db agnostic library, (this is more of rant for myself as i am in the same boat need temporal data for a different db from mssql) .

aloksharma1 avatar Dec 31 '23 11:12 aloksharma1

Everyone, note that PG has great support for timestamp and date ranges (which other databases don't). This makes it pretty easy to have e.g. a daterange column expressing when the row was "valid", and then efficiently filtering by it. That can be seen as a sort of temporal table feature, without the special syntax like e.g. in SQL Server.

I actually think the PG way of supporting range types properly and allowing you to build stuff on top of them (temporal tables or otherwise) is a much better approach than e.g. the SQL Server feature.

But of course that doesn't really help people trying to migrate from SQL Server etc..

roji avatar Dec 31 '23 11:12 roji