Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions tests/distinct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,14 @@ func TestDistinctWithVaryingCase(t *testing.T) {
}

func TestDistinctComputedColumn(t *testing.T) {
t.Skip()
type UserWithComputationColumn struct {
ID int64 `gorm:"primary_key"`
Name string
Col int64
}

if err := DB.Migrator().DropTable(&UserWithComputationColumn{}); err != nil {
t.Fatalf("failed to drop table: %v", err)
t.Logf("failed to drop table: %v", err)
}
if err := DB.AutoMigrate(&UserWithComputationColumn{}); err != nil {
t.Fatalf("failed to migrate table: %v", err)
Expand All @@ -163,8 +162,8 @@ func TestDistinctComputedColumn(t *testing.T) {

var computedRecords []int
if err := DB.
Table("USER_WITH_COMPUTATION_COLUMNS").
Select("DISTINCT col * 12 as Computed_Column").
Table("user_with_computation_columns").
Select("DISTINCT \"col\" * 12 as Computed_Column").
Order("Computed_Column").
Pluck("Computed_Column", &computedRecords).Error; err != nil {
t.Fatalf("failed to query distinct Computed Columns: %v", err)
Expand All @@ -174,7 +173,6 @@ func TestDistinctComputedColumn(t *testing.T) {
}

func TestDistinctWithAggregation(t *testing.T) {
t.Skip()
type UserWithComputationColumn struct {
ID int64 `gorm:"primaryKey"`
Name string
Expand All @@ -197,21 +195,21 @@ func TestDistinctWithAggregation(t *testing.T) {
}

if err := DB.Create(&records).Error; err != nil {
t.Fatalf("failed to insert test users: %v", err)
t.Logf("failed to insert test users: %v", err)
}

var result struct {
Sum int64
Sum float64
Avg float64
Count int64
Count int
}

err := DB.
Table("USER_WITH_COMPUTATION_COLUMNS").
Table("user_with_computation_columns").
Select(`
SUM(DISTINCT col) AS Sum,
AVG(DISTINCT col) AS Avg,
COUNT(DISTINCT col) AS Count
SUM(DISTINCT "col") AS "sum",
AVG(DISTINCT "col") AS "avg" ,
COUNT(DISTINCT "col") AS "count"
`).Scan(&result).Error

if err != nil {
Expand Down
Loading