我使用golang lib sqlx并尝试将json插入jsonb字段并出错:
预计为零,但得到了:& pq.Error {严重性:"错误",代码:" 42601", 消息:"未终止的带引号的标识符在\" \" \"",详细信息:"", 提示:"",位置:" 73",InternalPosition:"",InternalQuery:"", 其中:"",架构:"",表:"",列:"",DataTypeName:" &#34 ;, 约束:"",文件:" scan.l",行:" 1083",例程:" scanner_yyerror"}
代码:
type AuthenticationsAuthenticationsSQL struct {
AccountId sql.NullInt64 `db:"account_id"`
Success sql.NullBool `db:"success"`
Metadata types.JSONText `db:"metadata"`
}
func (aa *AuthenticationsAuthentications) Insert(params *AuthenticationsAuthenticationsSQL) error {
sqls := `INSERT INTO authentications.authentications(account_id, success, metadata)
VALUES (:account_id, :success, :metadata)`
if _, err := aa.client.NamedExec(sqls, params); err != nil {
return err
}
return nil
}
我如何使用
err = service.AuthenticationsAuthentications.Insert(&AuthenticationsAuthenticationsSQL{
AccountId: sql.NullInt64{Int64: accountId, Valid: true},
Success: sql.NullBool{Valid: true, Bool: true},
Metadata: types.JSONText(b),
})