From 6e7161f238551efbb9bf72c61ce0765c52966699 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Tue, 10 Jul 2018 11:14:00 +0200 Subject: [PATCH] add aggregates when adding group by --- public/app/plugins/datasource/postgres/postgres_query.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/public/app/plugins/datasource/postgres/postgres_query.ts b/public/app/plugins/datasource/postgres/postgres_query.ts index 71cf1ae7fce..2c01417ad12 100644 --- a/public/app/plugins/datasource/postgres/postgres_query.ts +++ b/public/app/plugins/datasource/postgres/postgres_query.ts @@ -96,6 +96,14 @@ export default class PostgresQuery { partModel.part.params = ['1m', 'none']; } + // add aggregates when adding group by + for (let i = 0; i < this.target.select.length; i++) { + var selectParts = this.target.select[i]; + if (!selectParts.some(part => part.type === 'aggregate')) { + selectParts.splice(1, 0, { type: 'aggregate', params: ['avg'] }); + } + } + this.updateProjection(); }