+1
-7
@@ -3191,13 +3191,7 @@ SELECT
|
||||
THEN 100.0 * agg.gold_hits / agg.samples_present
|
||||
ELSE NULL END AS "Gold"
|
||||
FROM agg
|
||||
JOIN totals ON totals."Vcenter" = agg."Vcenter"
|
||||
GROUP BY
|
||||
agg."InventoryId", agg."Name", agg."Vcenter", agg."VmId", agg."EventKey", agg."CloudId",
|
||||
agg."Datacenter", agg."Cluster", agg."Folder",
|
||||
agg."IsTemplate", agg."PoweredOn", agg."SrmPlaceholder", agg."VmUuid",
|
||||
agg.any_creation, agg.any_deletion, agg.first_present, agg.last_present,
|
||||
totals.total_samples, totals.max_snapshot;
|
||||
JOIN totals ON totals."Vcenter" = agg."Vcenter";
|
||||
`, unionQuery, tableName)
|
||||
return insert, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuildDailySummaryInsertDoesNotGroupFinalAggJoin(t *testing.T) {
|
||||
query, err := BuildDailySummaryInsert("inventory_daily_summary_20260101", "SELECT 1")
|
||||
if err != nil {
|
||||
t.Fatalf("BuildDailySummaryInsert failed: %v", err)
|
||||
}
|
||||
|
||||
if !strings.Contains(query, `FROM agg
|
||||
JOIN totals ON totals."Vcenter" = agg."Vcenter";`) {
|
||||
t.Fatalf("expected final agg/totals join with terminator, query tail changed unexpectedly")
|
||||
}
|
||||
|
||||
if strings.Contains(query, `FROM agg
|
||||
JOIN totals ON totals."Vcenter" = agg."Vcenter"
|
||||
GROUP BY`) {
|
||||
t.Fatalf("unexpected final GROUP BY after agg/totals join; this breaks Postgres SQLSTATE 42803")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user