I am trying to update a Jsonb column value for a particular row. I ran the query
UPDATE instruction.file SET "details" = (jsonb_set("details",'{"UploadBy"}','"test@test.com"'::jsonb, true)) WHERE id=820;
this works fine in the pgAdmin3.
When I tried to do the same in my Go code. Iam getting the error:"pq: invalid input syntax for type json"
My Go code:
func main() {
uname := "test@test.com"
err := Init() //Db init
if err != nil {
fmt.Println("Error", err)
return
}
result, err1 := Db.Exec("UPDATE instruction.file SET \"details\" = (jsonb_set(\"details\",'{\"UploadBy\"}',$1::jsonb, true)) WHERE id=$2", uname, "820")
if err1 != nil {
fmt.Println("Error", err1)
return
}
n, err1 := result.RowsAffected()
if err1 != nil {
fmt.Println("Error", err1)
return
}
if n != 1 {
err1 = errors.New("Unable to update instruction.file")
fmt.Println("Error", err1)
return
}
fmt.Println("Success")
return
}