-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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 "INSERT INTO … SELECT … AS OF timestamp" Query #18672
Comments
Thank you for the feature request! This is a duplicate of #11703 |
@nullnotnil No, #11703 is about using SELECT `before`.id`, `before`.`value`, `after`.`value`
FROM `values` AS OF (NOW() - INTERVAL 1 HOUR) AS `before`
INNER JOIN `values` AS `after`
ON `before`.`id` = `after`.`id` and in particular the presented example, using INSERT INTO employees
(SELECT * FROM employees
AS OF TIMESTAMP
TO_TIMESTAMP('2004-04-04 09:30:00', 'YYYY-MM-DD HH:MI:SS')
WHERE last_name = 'Chung'); Note that CrDB has these specific examples: -- invalid
SELECT * FROM (SELECT * FROM t AS OF SYSTEM TIME '-4h'), u
SELECT * FROM (SELECT * FROM t AS OF SYSTEM TIME '-4h') tp
JOIN u ON tp.x = u.y
AS OF SYSTEM TIME '-4h' -- same timestamp as above - OK.
WHERE x < 123; implying SQL Server's |
#11703 has a good title "Support I listed some statements CockraochDB supported in #11703 (comment), maybe we can consider them as well. |
Your description of the syntax in ANSI SQL and other database systems inspired me about what syntax we should use in TiDB. Can we close one issue and discuss them in one place? |
Duplicate of #11703 |
@SunRunAway I have explained previously that it is not a duplicate of #11703 in #18672 (comment). (Plus #11703 was closed-as-dupe to this issue in #11703 (comment) making this a silly cyclic dependency (#11703 should be a dupe of #22765, not this issue)) I have also checked v6.5.0 and nightly that the matching Oracle DB feature mentioned at the top is still not supported.
I'm going to reopen given that there's no justification why my comment above is no longer valid, and edited the title to clarify the desired feature. |
Thanks for your patient explanation. I’ve changed title to an explicit syntax for better understanding for other people. |
Feature Request
(On behalf of Marvin Jin)
Is your feature request related to a problem? Please describe:
TiDB using TiKV storage supports reading historical data using the
@@tidb_snapshot
system variable. However, you are not allowed to write anything while@@tidb_snapshot
is set, so it is not possible to aggregate these historical data unless using external programs (backup/restore).Describe the feature you'd like:
In Oracle DB, there is an
AS OF
clause to read from a historical table without affecting the global timestamp.A similar syntax exists on CockroachDB (but not sure if INSERT/SELECT works):
ANSI SQL has the "Temporal" feature, which is supported on MariaDB, MS SQL server, DB2 and more. When a table is set to be "temporal", the following syntax is available:
Note, however, the
system_time
refers to a PERIOD bound to two columns of the tableold_table
, which is a totally different concept from@@tidb_snapshot
.Describe alternatives you've considered:
@@tidb_snapshot
.SELECT INTO OUTFILE
in historical query andLOAD DATA INFILE
to restore data to current time.Teachability, Documentation, Adoption, Migration Strategy:
The text was updated successfully, but these errors were encountered: