官术网_书友最值得收藏!

Extracting timestamps

As we previously mentioned, Cassandra has special capabilities for the timeuuid type, which includes extracting the timestamp that's encoded in these UUIDs. We can see this in action using the DATEOF function:

SELECT "username", "id", "body", DATEOF("id") 
FROM "user_status_updates";

The DATEOF function instructs Cassandra to return a result column containing the timestamp at which the given column's UUID value was created. We now have access to information encoded in the id column that was previously obscure:

If you're following along with your CQL shell, you'll notice that the dates do not tell you when the rows were created but when the UUIDs in the id column were generated. Since we're using UUIDs that I generated when writing this book, we'll see that the creation timestamp shows an older time.

While the DATEOF output is very readable, the timestamps only offer precision at the second level. For a more precise representation of the timestamp at which the UUIDs were generated, use the UNIXTIMESTAMPOF function instead:

SELECT "username", "id", "body", UNIXTIMESTAMPOF("id") 
FROM "user_status_updates";

The UNIXTIMESTAMPOF function returns the timestamp represented as the number of milliseconds since January 1, 1970 at midnight UTC:

主站蜘蛛池模板: 皋兰县| 西畴县| 健康| 高青县| 延津县| 肃宁县| 呼图壁县| 子长县| 翁源县| 北票市| 钟山县| 鲁山县| 拉孜县| 五河县| 和硕县| 淮南市| 高要市| 武安市| 古蔺县| 林甸县| 城固县| 高平市| 双牌县| 林芝县| 齐河县| 施甸县| 司法| 河池市| 昂仁县| 潼南县| 花莲县| 衡山县| 梧州市| 洛川县| 东莞市| 长乐市| 四子王旗| 大姚县| 黎平县| 高雄县| 应城市|