diff --git a/public/app/plugins/datasource/postgres/postgres_query.ts b/public/app/plugins/datasource/postgres/postgres_query.ts index 7826b455e99..5b0bd539abe 100644 --- a/public/app/plugins/datasource/postgres/postgres_query.ts +++ b/public/app/plugins/datasource/postgres/postgres_query.ts @@ -220,7 +220,7 @@ export default class PostgresQuery { query += '\n ' + this.buildTimeColumn(); if (this.hasMetricColumn()) { - query += '\n ' + this.buildMetricColumn(); + query += ',\n ' + this.buildMetricColumn(); } query += this.buildValueColumns(); diff --git a/public/app/plugins/datasource/postgres/specs/postgres_query.jest.ts b/public/app/plugins/datasource/postgres/specs/postgres_query.jest.ts index 9559cd3c350..42f1d5243d5 100644 --- a/public/app/plugins/datasource/postgres/specs/postgres_query.jest.ts +++ b/public/app/plugins/datasource/postgres/specs/postgres_query.jest.ts @@ -103,5 +103,9 @@ describe('PostgresQuery', function() { let query = new PostgresQuery(target, templateSrv); expect(query.buildQuery()).toBe(result); + + query.target.metricColumn = 'm'; + result = 'SELECT\n t AS "time",\n m AS metric,\n value\nFROM public.table\nORDER BY 1'; + expect(query.buildQuery()).toBe(result); }); });