database - 有没有办法在Golang中实现cassandra "decimal"数据类型

标签 database go cassandra abstract-data-type

我有一个设置为十进制的数据库字段,而在我的 Go 项目中,我在选择可以使用哪种数据类型时遇到问题。 每次我向代码发送创建请求时,都会收到“无法将‘小数’编码到#golang datatype#

这是我的数据库架构

CREATE TABLE transaction(
organization_id timeuuid,
month text,
employee_id timeuuid,
id timeuuid,
employee_name text,
amount decimal,
deductions int,
date_approved date,
PRIMARY KEY ((organization_id, month), id)

)

我的 golang 模型看起来像这样

type WageGarnishment struct {
ID            gocql.UUID `json:"id"`
organizationID            gocql.UUID `json:"organization_id"`
Month          string     `json:"month"`
Amount        Float64    `json:"amount"`
Deductions    uint       `json:"deductions"`
EffectiveDate time.Time  `json:"effective_date"`
DateApproved  time.Time  `json:"date_approved"`
EmployeeSummary

}

无论我的金额字段中的数据类型如何,我都会收到此错误:

Error #01: can not marshal float64 into decimal

感谢您提前提供帮助

最佳答案

如果你查看documentation for Gocql package ,然后您将看到 decimal 映射到 Go 的 infDec 数据类型(请参阅 its doc ),因此您需要使用它而不是 Float64.

关于database - 有没有办法在Golang中实现cassandra "decimal"数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71125652/

相关文章:

mysql - 正确查询以选择 MySQL 中来自 friend 的所有消息

mysql - 一个或多个 MySQL 大表(性能)

database - 在 for 循环中使用 db 连接时内存泄漏

json - 如何以 Sendgrid API 接受的格式将 html 嵌入到 json 中?

java - 使用 Java Cassandra 客户端以编程方式设置日志级别

scala - 在 Spark 中读取文件时出错

database - SQL Plus SP2-0306 来自 SQL 文件中的 CONNECT 行,相同的凭据在批处理文件中有效

SQL 足球积分表最近 5 场比赛

go - 整数的 Protocol Buffer 零值

csv - 无法将 '2012/11/11' 强制转换为格式化日期(长)