Insert an array in a column with type jsonb in postgres using golang sqlx

Viewed 904

When I create and store using the below logic, it creates an object. What I want to create is an array of objects and I want to handle this on the server side and not force the UI to send me an array of objects, in which case it does get saved as an array of objects

sqlstatement := `INSERT INTO TABLE (THREAD) VALUES ($1);`  
tx.MustExec(sqlstatement,t.Thread)

type Create struct {
    Thread  json.RawMessage `json:"thread"`
}

The created JSONB object is of type

{
    thread: {
        data: temp
    }
}

What I am looking to create is:

{
    thread: [{
        data: temp
    }]
}
0 Answers
Related