From cd1c88b4d4ec77f4a0099e42955d3a2d9c4ce25f Mon Sep 17 00:00:00 2001 From: Ian Ngethe Muchiri <100555904+ianmuchyri@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:02:12 +0300 Subject: [PATCH] NOISSUE - Update Aggregation SQL query (#2111) Signed-off-by: ianmuchyri --- readers/timescale/messages.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readers/timescale/messages.go b/readers/timescale/messages.go index e16304ab5e..aa1589d033 100644 --- a/readers/timescale/messages.go +++ b/readers/timescale/messages.go @@ -42,7 +42,7 @@ func (tr timescaleRepository) ReadAll(chanID string, rpm readers.PageMetadata) ( // If aggregation is provided, add time_bucket and aggregation to the query if rpm.Aggregation != "" { - q = fmt.Sprintf(`SELECT EXTRACT(epoch FROM time_bucket('%s', to_timestamp(time/1000))) AS time, %s(value) AS value FROM %s WHERE %s GROUP BY 1 ORDER BY time DESC LIMIT :limit OFFSET :offset;`, rpm.Interval, rpm.Aggregation, format, fmtCondition(rpm)) + q = fmt.Sprintf(`SELECT EXTRACT(epoch FROM time_bucket('%s', to_timestamp(time/1000))) *1000 AS time, %s(value) AS value FROM %s WHERE %s GROUP BY 1 ORDER BY time DESC LIMIT :limit OFFSET :offset;`, rpm.Interval, rpm.Aggregation, format, fmtCondition(rpm)) totalQuery = fmt.Sprintf(`SELECT COUNT(*) FROM (SELECT EXTRACT(epoch FROM time_bucket('%s', to_timestamp(time/1000))) AS time, %s(value) AS value FROM %s WHERE %s GROUP BY 1) AS subquery;`, rpm.Interval, rpm.Aggregation, format, fmtCondition(rpm)) }