gorm操作数组的test
package test import ( "fmt" "github.com/lib/pq" "gorm.io/driver/postgres" "gorm.io/gorm" "testing" ) func GetDB() *gorm.DB { dsn := "host=127.0.0.1 user= password= dbname= port=5432 sslmode=disable TimeZone=Asia/Shanghai" db, _ := gorm.Open(postgres.Open(dsn), &gorm.Config{}) return db } type Kenyou struct { Id uint64 `gorm:"column:id" json:"id"` Items pq.Int64Array `gorm:"column:items;type:text[]" json:"items"` } func TestClean(t *testing.T) { //dt := []int64{34, 4, 16} var tmp []Kenyou conn := GetDB().Table("t_kenyon") //err := conn.Debug().Create(&tmp).Error err := conn.Debug().Where("items @> ?", pq.Int64Array{1}).Find(&tmp).Error if err != nil { t.Log("111111111") t.Log(err.Error()) } for _, v := range tmp { fmt.Print(v) } }