@@ -138,15 +138,14 @@ func TestDistinctWithVaryingCase(t *testing.T) {
138
138
}
139
139
140
140
func TestDistinctComputedColumn (t * testing.T ) {
141
- t .Skip ()
142
141
type UserWithComputationColumn struct {
143
142
ID int64 `gorm:"primary_key"`
144
143
Name string
145
144
Col int64
146
145
}
147
146
148
147
if err := DB .Migrator ().DropTable (& UserWithComputationColumn {}); err != nil {
149
- t .Fatalf ("failed to drop table: %v" , err )
148
+ t .Logf ("failed to drop table: %v" , err )
150
149
}
151
150
if err := DB .AutoMigrate (& UserWithComputationColumn {}); err != nil {
152
151
t .Fatalf ("failed to migrate table: %v" , err )
@@ -163,8 +162,8 @@ func TestDistinctComputedColumn(t *testing.T) {
163
162
164
163
var computedRecords []int
165
164
if err := DB .
166
- Table ("USER_WITH_COMPUTATION_COLUMNS " ).
167
- Select ("DISTINCT col * 12 as Computed_Column" ).
165
+ Table ("user_with_computation_columns " ).
166
+ Select ("DISTINCT \" col\" * 12 as Computed_Column" ).
168
167
Order ("Computed_Column" ).
169
168
Pluck ("Computed_Column" , & computedRecords ).Error ; err != nil {
170
169
t .Fatalf ("failed to query distinct Computed Columns: %v" , err )
@@ -174,7 +173,6 @@ func TestDistinctComputedColumn(t *testing.T) {
174
173
}
175
174
176
175
func TestDistinctWithAggregation (t * testing.T ) {
177
- t .Skip ()
178
176
type UserWithComputationColumn struct {
179
177
ID int64 `gorm:"primaryKey"`
180
178
Name string
@@ -197,21 +195,21 @@ func TestDistinctWithAggregation(t *testing.T) {
197
195
}
198
196
199
197
if err := DB .Create (& records ).Error ; err != nil {
200
- t .Fatalf ("failed to insert test users: %v" , err )
198
+ t .Logf ("failed to insert test users: %v" , err )
201
199
}
202
200
203
201
var result struct {
204
- Sum int64
202
+ Sum float64
205
203
Avg float64
206
- Count int64
204
+ Count int
207
205
}
208
206
209
207
err := DB .
210
- Table ("USER_WITH_COMPUTATION_COLUMNS " ).
208
+ Table ("user_with_computation_columns " ).
211
209
Select (`
212
- SUM(DISTINCT col) AS Sum ,
213
- AVG(DISTINCT col) AS Avg ,
214
- COUNT(DISTINCT col) AS Count
210
+ SUM(DISTINCT " col" ) AS "sum" ,
211
+ AVG(DISTINCT " col" ) AS "avg" ,
212
+ COUNT(DISTINCT " col" ) AS "count"
215
213
` ).Scan (& result ).Error
216
214
217
215
if err != nil {
0 commit comments