Skip to content

Commit b7ced94

Browse files
authored
fix: prevent repetition of template IDs in template_usage_by_day (#8693)
1 parent f827829 commit b7ced94

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

coderd/database/queries.sql.go

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/insights.sql

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,16 @@ WITH d AS (
9494
GROUP BY ts.from_, ts.to_, was.user_id
9595
), template_ids AS (
9696
SELECT
97-
from_,
98-
array_agg(DISTINCT template_id) AS ids
99-
FROM usage_by_day, unnest(template_ids) template_id
97+
template_usage_by_day.from_,
98+
array_agg(template_id) AS ids
99+
FROM (
100+
SELECT DISTINCT
101+
from_,
102+
unnest(template_ids) AS template_id
103+
FROM usage_by_day
104+
) AS template_usage_by_day
100105
WHERE template_id IS NOT NULL
101-
GROUP BY from_, template_ids
106+
GROUP BY template_usage_by_day.from_
102107
)
103108

104109
SELECT

0 commit comments

Comments
 (0)