postgresql postgres.Jsonb


//postgres.Jsonb 处理
type homeWorkQuestionIds struct {
		QuestionIDs           postgres.Jsonb `json:"question_ids"`   
	}

var homeworkRes []homeWorkQuestionIds

db.Model(&lesson.LessonHomeWork{}).
		Select("question_ids").
		Joins("LEFT JOIN xxxx on lesson_home_works.home_work_id = home_works.id").
		Where("ccc.lesson_id = ?", lessonIDQuery).
		Scan(&homeworkRes)

var total []uint
	var request []questionListRequest
	for i := range homeworkRes{
		var questionIds []uint
		json.Unmarshal(homeworkRes[i].QuestionIDs.RawMessage,&questionIds)
		total = append(total,questionIds...)
	}

 jsonb_array_length ( home_works.question_ids )

type HomeWork struct {
    QuestionIDs           postgres.Jsonb `json:"question_ids"`   

}


type homeWorkRequest struct {

    QuestionIDs  []uint `json:"question_ids"`  

}

questionIDsByte, err := json.Marshal(request.QuestionIDs)
homeWorkModel.QuestionIDs = postgres.Jsonb{RawMessage: questionIDsByte}
原文地址:https://www.cnblogs.com/ithubb/p/15767149.html