Skip to content

Commit

Permalink
NOISSUE - Update Aggregation SQL query (#2111)
Browse files Browse the repository at this point in the history
Signed-off-by: ianmuchyri <[email protected]>
  • Loading branch information
ianmuchyri authored Mar 12, 2024
1 parent 0affd8b commit cd1c88b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion readers/timescale/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down

0 comments on commit cd1c88b

Please sign in to comment.