1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Cassandra のタイムスタンプ型は文字列で指定する

Posted at

自分がデータベースでよく使う型で一番手が止まるのは、タイムスタンプ型です。
例えば Oracle だと to_date で日時を指定してみたり、それでも上手く指定できずに between を使って select 文を書いたりしています。

一方 Cassandra に関しては、タイムスタンプ型の指定がとても大らかで助かったので、まとめてみました。
※ cqlsh は 3.4.4 を使っています。

Cassandra のタイムスタンプ型は文字列で指定する

以下のパターンは、全て Cassandra のタイムスタンプ型として成立します。

  • 2019-04-15 (その日の0時0分として利用ができる)
  • 2019-04-15 00:00 (分単位)
  • 2019-04-15 00:00:00 (秒単位)
  • 2019-04-15 00:00:00+0000 (4桁のタイムゾーンを指定。例は GMT)
  • 2019-04-15 00:00:00Z (cqlsh や環境変数で指定された時差を使用)

便利ですね。

※ 他にも Cassandra は時刻に関する表現として timeuuid 関数を持っています。
こちらは必ずユニークな値で保存でき、データの一意性を保ちたい場合に便利です。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?