浏览代码

add aggregates when adding group by

Sven Klemm 7 年之前
父节点
当前提交
6e7161f238
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      public/app/plugins/datasource/postgres/postgres_query.ts

+ 8 - 0
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();
   }