From 2cae966e6ccfb50e6eb7432ed425a06eed600ed9 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Thu, 2 Aug 2018 21:40:15 +0200 Subject: [PATCH] use $__timeGroupAlias macro --- .../datasource/postgres/postgres_query.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/datasource/postgres/postgres_query.ts b/public/app/plugins/datasource/postgres/postgres_query.ts index 9715665fd4b..fb6fa59ada1 100644 --- a/public/app/plugins/datasource/postgres/postgres_query.ts +++ b/public/app/plugins/datasource/postgres/postgres_query.ts @@ -92,7 +92,7 @@ export default class PostgresQuery { } } - buildTimeColumn() { + buildTimeColumn(alias = true) { let timeGroup = this.hasTimeGroup(); let query; @@ -103,9 +103,16 @@ export default class PostgresQuery { } else { args = timeGroup.params[0]; } - query = '$__timeGroup(' + this.target.timeColumn + ',' + args + ')'; + if (alias) { + query = '$__timeGroupAlias(' + this.target.timeColumn + ',' + args + ')'; + } else { + query = '$__timeGroup(' + this.target.timeColumn + ',' + args + ')'; + } } else { - query = this.target.timeColumn + ' AS "time"'; + query = this.target.timeColumn; + if (alias) { + query += ' AS "time"'; + } } return query; @@ -162,9 +169,7 @@ export default class PostgresQuery { if (this.hasMetricColumn()) { overParts.push('PARTITION BY ' + this.target.metricColumn); } - if (!aggregate) { - overParts.push('ORDER BY ' + this.target.timeColumn); - } + overParts.push('ORDER BY ' + this.buildTimeColumn(false)); let over = overParts.join(' '); let curr: string;