我可以使用触发器获取表上的 LastUpdated 列吗?

发布于 2025-01-12 16:56:39 字数 149 浏览 1 评论 0原文

我想在我的 cassandra 表上添加一个 lastUpdated 列,并在更新行时由 cassandra 自动填充该列。

cassandra 有触发器可以做到这一点吗?

目标是不必更新代码库,只需进行数据库迁移即可使其工作。

I want to add a lastUpdated column on my cassandra tables, and have this column autopopulated by cassandra whenever a row is updated.

Does cassandra have triggers that could do this?

The goal is not to have to update code base, just a db migration to make this work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墟烟 2025-01-19 16:56:39

Cassandra 存储每个列/行/分区的写入时间。事实上,这就是协调器用来确定数据的最新版本并将其返回给客户端的方法。

根据您的需求,您可以将此元数据用于您的目的,而无需单独存储。有一个内置函数WRITETIME(),它返回写入数据时的时间戳(以微秒为单位)(详细信息在这里)。

关于数据库触发器,它们存在于 Cassandra 中,但 5(也许 7)年来没有针对此功能做太多工作,因此我个人不建议使用它们。我认为触发器始终被认为是实验性的,并且从未继续发展。事实上,大约 5 年前,它们在 DataStax Enterprise 中已被弃用。干杯!

Cassandra stores the write time for each column/row/partition. In fact, this is what the coordinators use to determine the latest version of the data and returns it to the clients.

Depending on what you're after, you can use this metadata for your purposes without having to store it separately. There is a built-in function WRITETIME() that returns the timestamp in microseconds for when the data was written (details here).

On the subject of database triggers, they exist in Cassandra but there hasn't been much work done for this functionality for 5 (maybe 7) years so I personally wouldn't recommend their use. I think triggers were always considered experimental and never moved on. In fact, they were deprecated in DataStax Enterprise around 5 years ago. Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文