Filtering by a list of values with GORM

04/07/2020 gorm sql postgresql


If one has a list of values, for example 1,2,3, to filter data by this this one should use ANY and pq.Array constructions:

var priceIDs = []uint{1,2,3}
if err := db.Model(prices).Where("id = ANY(?)", pq.Array(priceIDs)).Find(&prices).Error; err != nil {
	return err
}

Related articles