Skip to content
This repository has been archived by the owner on Jun 6, 2019. It is now read-only.

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

Open
sankeyou opened this issue Jul 27, 2017 · 3 comments
Open

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

sankeyou opened this issue Jul 27, 2017 · 3 comments

Comments

@sankeyou
Copy link

sankeyou commented Jul 27, 2017

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 允许为空,会出错,插""是不行的,求更新!

@lunny
Copy link
Member

lunny commented Jul 27, 2017

Name interface{}?

@sankeyou
Copy link
Author

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

@lunny
Copy link
Member

lunny commented Jul 29, 2017

null也是JSON支持的吧

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants