我可以用哪种格式将 golang 的 time.Time 存储在 scylladb 中?
In which format can I store golang's time.Time in scylladb?
我想知道 scylladb 中哪种格式的数据类型可以容纳 golang 的 time.Time 值。我尝试使用 'time' 类型,但它会生成错误。
这是我收到的错误:
can not marshal time.Time into time
查看 Marshal function 的 Golang 文档。不确定你的时间在 Cassandra table 中是如何定义的,但时间类型的条目如下所示:
CQL Type | Go Type
---------------------------------------------------------------------------------
time | int64 | nanoseconds since start of day
time | time.Duration | duration since start of day
timestamp | int64 | milliseconds since Unix epoch
timestamp | time.Time |
uuid, timeuuid | gocql.UUID |
uuid, timeuuid | [16]byte | raw UUID bytes
uuid, timeuuid | []byte | raw UUID bytes, length must be 16 bytes
uuid, timeuuid | string | hex representation, see ParseUUID
date | int64 | milliseconds since Unix epoch to start of day (in UTC)
date | time.Time | start of day (in UTC)
date | string | parsed using "2006-01-02" format
duration | int64 | duration in nanoseconds
duration | time.Duration |
duration | gocql.Duration |
duration | string | parsed with time.ParseDuration
鉴于此,您应该能够为 time.Time
使用 timestamp
或 date
。
我想知道 scylladb 中哪种格式的数据类型可以容纳 golang 的 time.Time 值。我尝试使用 'time' 类型,但它会生成错误。 这是我收到的错误:
can not marshal time.Time into time
查看 Marshal function 的 Golang 文档。不确定你的时间在 Cassandra table 中是如何定义的,但时间类型的条目如下所示:
CQL Type | Go Type
---------------------------------------------------------------------------------
time | int64 | nanoseconds since start of day
time | time.Duration | duration since start of day
timestamp | int64 | milliseconds since Unix epoch
timestamp | time.Time |
uuid, timeuuid | gocql.UUID |
uuid, timeuuid | [16]byte | raw UUID bytes
uuid, timeuuid | []byte | raw UUID bytes, length must be 16 bytes
uuid, timeuuid | string | hex representation, see ParseUUID
date | int64 | milliseconds since Unix epoch to start of day (in UTC)
date | time.Time | start of day (in UTC)
date | string | parsed using "2006-01-02" format
duration | int64 | duration in nanoseconds
duration | time.Duration |
duration | gocql.Duration |
duration | string | parsed with time.ParseDuration
鉴于此,您应该能够为 time.Time
使用 timestamp
或 date
。