Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support system versioning for views #18

Open
knutwannheden opened this issue Feb 19, 2021 · 6 comments
Open

Support system versioning for views #18

knutwannheden opened this issue Feb 19, 2021 · 6 comments

Comments

@knutwannheden
Copy link

SQL Server supports querying views with the AS OF clause and SQL Server will transparently apply the clause to all temporal tables participating in the view definition's query. See https://docs.microsoft.com/en-us/sql/relational-databases/tables/querying-data-in-a-system-versioned-temporal-table?view=sql-server-ver15#using-views-with-as-of-sub-clause-in-temporal-queries for details.

I don't know if this feature is defined by the SQL standard or not, but it looks very powerful indeed.

@xocolatl
Copy link
Owner

That would be a really nice feature to have in core PostgreSQL. I don't see how this extension can do it without hindering more than helping. Also, what should happen if the view uses an AS OF clause in its query? Should the AS OF on the view override it, or somehow combine them, or what?

The standard does not allow system versioning on anything but regular persistent base tables.

If you have any workable ideas on how it could be done, I'll be happy to review your patch or write one myself.

@knutwannheden
Copy link
Author

I was just looking for a way to define a point in time in a single place using which all temporal tables will be queried. Oracle's flashback technology provides some mechanism like this, IIRC (but I may well be wrong about this, since it is quite some time ago I worked with Oracle flashback). Then I stumbled across this SQL Server feature, which looks really nice and thought that this would be nice for PostgreSQL and I couldn't find a better place to report this than here.

I could of course try out how SQL Server behaves if it already has an AS OF clause on some of the tables it selects from and report my results back here. But that on its own isn't very valuable, I guess...

@knutwannheden
Copy link
Author

FWIW: I did perform the test now and there is an error reported when I execute the query if the view contains an AS OF clause already: SQL Error [13590] [S0001]: Temporal FOR SYSTEM_TIME clause can only be set once per temporal table. 'example' has more than one temporal FOR SYSTEM_TIME clause.

@knutwannheden
Copy link
Author

The Oracle feature I was referring to is the DBMS_FLASHBACK PL/SQL package (see https://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_flashback.htm#ADFNS01009). It provides procedures like ENABLE_AT_TIME.

@knutwannheden
Copy link
Author

knutwannheden commented Feb 20, 2021

MariaDB also appears to allow querying views with the AS OF clause: https://mariadb.com/kb/en/system-versioned-tables/#views-and-subqueries

Also it offers a system variable offering a feature equivalent to that of Oracle's stored procedure: https://mariadb.com/kb/en/system-versioned-tables/#views-and-subqueries

@df7cb
Copy link
Collaborator

df7cb commented Feb 20, 2021

I'll just drop that here without comment. :)

https://www.postgresql.org/docs/6.3/c0503.htm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants