【发布时间】:2018-09-27 15:33:11
【问题描述】:
我有一个维护产品数据的表。 我每隔几分钟进行一次 API 调用后更新此表。
假设我有这张桌子。
create table products(
id int,
name text,
created timestamp,
updated timestamp,
primary_key(id)
);
所以我在 00:00:00 进行 API 调用,我得到了产品列表
[
{id:1, name:'product1'},
{id:2, name:'product2'}
]
我将它插入到我的 cassandra 表中
id | name | created | updated
1 | Product1 | 1/1/2018 00:00:00| 1/1/2018 00:00:00
2 | Product2 | 1/1/2018 00:00:00| 1/1/2018 00:00:00
现在在 10 分钟后的第二次 API 调用中,用户删除了 Product1,但创建了 Product3,所以我得到 API 调用输出为
[
{id:2, name:'product2'},
{id:3, name:'product3'}
]
我将在我的 cassandra 表中更新它(因为我不想在决定是否插入或更新之前检查记录是否存在)但我想在我的不安查询中维护 product2 的创建时间,以便我知道产品的创建时间以及产品的生命周期。
我是否可以通过 now() 设置它来维护创建的时间戳而不在查询中指定它,然后我继续更新 updatetime 值?
我的桌子应该是这样的
id | name | created | updated
1 | Product1 | 1/1/2018 00:00:00 | 1/1/2018 00:00:00
2 | Product2 | 1/1/2018 00:00:00 | 1/1/2018 00:00:10
3 | Product3 | 1/1/2018 00:00:10 | 1/1/2018 00:00:10
【问题讨论】: