database - 我可以用哪种格式存储 golang 的 time.Time 在 scylladb 中?

标签 database go error-handling cassandra scylla

我想知道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

鉴于此,您应该能够使用 timestampdate 作为 time.Time

关于database - 我可以用哪种格式存储 golang 的 time.Time 在 scylladb 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66612298/

相关文章:

database - 为什么循环中的 Entity Framework Core 调用会抛出 InvalidOperationException?

go - 在Golang中执行之前如何停止AfterFunc

asp.net - 如何使用 elmah 记录警告

exception - 这是正确的异常处理的有效示例吗?

php - 如何获取PHP中的SQL Server触发器错误?

java - 如何测试java DBMS应用程序的性能

database - 如何在 Flutter 应用程序中最好地在本地存储和操作大型数据集

database - 一个实体可以有多个主键吗?模型

golang超时使用范围从 channel 读取

linux - 去/geany : configure build command