简体   繁体   English

不断更新从另一个表创建的表

[英]Keep update a table created from another table

In CrateDB, after creating a table from data of another table, is it possible to keep the new table updated with the insertion of new lines from the original table?在 CrateDB 中,从另一个表的数据创建一个表后,是否可以通过从原始表中插入新行来保持新表的更新?

Query to create the new_table from enter code here :查询以从enter code here创建new_table

CREATE TABLE "schema"."new_table" AS
SELECT
state,
time,
time - LAG(time, -1, time) OVER (ORDER BY time DESC) AS duration
FROM "schema"."original_table"
ORDER BY timeDESC;

Query I run periodically to keep it the new_table updated, and which I would like to avoid using:查询我定期运行以保持new_table更新,我想避免使用:

INSERT INTO "schema"."new_table"
SELECT
process,
time,
time- LAG(time, -1, time) OVER (ORDER BY time DESC) AS duration FROM "mtopcua_car"."original_table" newDataTable
WHERE NOT EXISTS (SELECT time FROM "schema"."new_table" WHERE time = newDataTable.time);

Thanks.谢谢。

Depending on how expensive the query is, a view might just do the job:根据查询的开销,一个视图可能就可以完成这项工作:

CREATE VIEW "schema"."new_view" AS
SELECT
    state,
    time,
    time - LAG(time, -1, time) OVER (ORDER BY time DESC) AS duration
FROM "schema"."original_table"
ORDER BY time DESC;

CrateDB documentation: https://crate.io/docs/crate/reference/en/5.1/general/ddl/views.html CrateDB 文档: https://crate.io/docs/crate/reference/en/5.1/general/ddl/views.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM