I'm trying to query for "distinct" values in a table. The idea is to run a query like this one:
SELECT DISTINCT fieldName FROM tableName WHERE ...
My attempt:
// distinct value struct
type DValue struct {
Value interface{} `gorm:"column:value"`
}
...
var items []DValue
result := db.
Table(tableName).
Distinct(fmt.Sprintf("%s AS value", dbColumnName)).
Order(fmt.Sprintf("%s asc", dbColumnName)).
Find(&items)
var values []interface{}
for _, item := range items {
values = append(values, item.Value)
}
return values, nil
The query runs like it should and everything seems to be working fine. I am getting an error like this in the logs: [error] unsupported data type: 0x140004b2890 every time.
The issue seems to be the fact that my Value is of type interface{} but I cannot really set it to anything else since I do not know what type the field is.
Is there a way to get around that and keep the ambiguous type?