我想知道scylladb中哪种格式的数据类型可以保存golang的time.Time值。我试过使用“时间”类型,但它会产生错误。 这是我收到的错误:
can not marshal time.Time into time
最佳答案
查看 Golang 的 Marshal function 文档.不确定您的时间在 Cassandra 表中是如何定义的,但时间类型的条目如下所示:
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
鉴于此,您应该能够使用 timestamp
或 date
作为 time.Time
。
关于database - 我可以用哪种格式存储 golang 的 time.Time 在 scylladb 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66612298/