cmd icon indicating copy to clipboard operation
cmd copied to clipboard

postgresql数据库的josnb是空类型,映射string后有bug

Open sankeyou opened this issue 7 years ago • 3 comments

postgresql数据库的josnb字段是允许为空 映射string后,插入数据时,字段不赋值,插入式给的是'' 不是nil 导致插入不进去,报错

模型 type Test struct { Id int xorm:"pk autoincr INT"Name stringxorm:"JSONB" }

访问数据库代码 test := model.Test{Id: 2} id, err := db.Insert(&test)

出错信息 [xorm] [info] 2017/07/27 14:28:04.194950 [SQL] INSERT INTO "test" ("id","name") VALUES ($1, $2) RETURNING "id" []interface {}{2, ""} pq: json类型使用了无效的输入语法

name是个jsonb 允许为空,会出错,插""是不行的,求更新!

sankeyou avatar Jul 27 '17 06:07 sankeyou

Name interface{}?

lunny avatar Jul 27 '17 15:07 lunny

@lunny 你觉的 name map[string]interface{} 怎么样,但是还是要解决那个空的问题 我测试如果映射成 map[string]interface{} 为空时 插入的是 'null'
这不合适吧?

sankeyou avatar Jul 28 '17 07:07 sankeyou

null也是JSON支持的吧

lunny avatar Jul 29 '17 03:07 lunny