Browse Source

add aggregates when adding group by

Sven Klemm 7 years ago
parent
commit
6e7161f238
1 changed files with 8 additions and 0 deletions
  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'];
       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();
     this.updateProjection();
   }
   }