From 9ba42f63f1694c86e47b46f8cfef701ad1ce842c Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Wed, 11 Jul 2018 12:33:37 +0200 Subject: [PATCH] Refactor metric column sql generation --- .../datasource/postgres/postgres_query.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/datasource/postgres/postgres_query.ts b/public/app/plugins/datasource/postgres/postgres_query.ts index c54b1b7f510..700875e145d 100644 --- a/public/app/plugins/datasource/postgres/postgres_query.ts +++ b/public/app/plugins/datasource/postgres/postgres_query.ts @@ -184,6 +184,7 @@ export default class PostgresQuery { if (interpolate) { query = this.templateSrv.replace(query, this.scopedVars, this.interpolateQueryStr); } + this.target.rawSql = query; return query; } @@ -206,6 +207,16 @@ export default class PostgresQuery { return query; } + buildMetricColumn(target) { + let query = ''; + + if (this.target.metricColumn !== 'None') { + query += ',' + this.target.metricColumn + ' AS metric'; + } + + return query; + } + buildValueColumns(target) { let query = ''; for (let i = 0; i < this.selectModels.length; i++) { @@ -271,11 +282,7 @@ export default class PostgresQuery { let query = 'SELECT '; query += this.buildTimeColumn(target); - - if (this.target.metricColumn !== 'None') { - query += ',' + this.target.metricColumn + ' AS metric'; - } - + query += this.buildMetricColumn(target); query += this.buildValueColumns(target); query += ' FROM ' + target.schema + '.' + target.table; @@ -285,7 +292,6 @@ export default class PostgresQuery { query += ' ORDER BY 1'; - this.target.rawSql = query; return query; } }