In which format can I store golang's time.Time in scylladb?

Viewed 371

I'm wondering which format of data type in scylladb can hold golang's time.Time value. I have tried with 'time' type, but it generates an error. Here the error I'm receiving:

can not marshal time.Time into time

1 Answers

Have a look at Golang's documentation for the Marshal function. Not sure how your time is defined in your Cassandra table, but the entries for time types look like this:

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

Given that, you should be able to use a timestamp or a date for time.Time.

Related