diff --git a/public/app/plugins/datasource/postgres/postgres_query.ts b/public/app/plugins/datasource/postgres/postgres_query.ts index d5bdf005e8f..7e49a8a149f 100644 --- a/public/app/plugins/datasource/postgres/postgres_query.ts +++ b/public/app/plugins/datasource/postgres/postgres_query.ts @@ -151,11 +151,7 @@ export default class PostgresQuery { if (func === 'first' || func === 'last') { query = func + '(' + query + ',' + this.target.timeColumn + ')'; } else { - if (windows) { - query = func + '(' + query + ' ORDER BY ' + this.target.timeColumn + ')'; - } else { - query = func + '(' + query + ')'; - } + query = func + '(' + query + ')'; } break; case 'percentile': 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 c1d5400d1fa..1e2b75417da 100644 --- a/public/app/plugins/datasource/postgres/specs/postgres_query.jest.ts +++ b/public/app/plugins/datasource/postgres/specs/postgres_query.jest.ts @@ -98,8 +98,8 @@ describe('PostgresQuery', function() { { type: 'window', params: ['increase'] }, ]; expect(query.buildValueColumn(column)).toBe( - '(CASE WHEN max(v ORDER BY time) >= lag(max(v ORDER BY time)) OVER (PARTITION BY host ORDER BY time) ' + - 'THEN max(v ORDER BY time) - lag(max(v ORDER BY time)) OVER (PARTITION BY host ORDER BY time) ELSE max(v ORDER BY time) END) AS "a"' + '(CASE WHEN max(v) >= lag(max(v)) OVER (PARTITION BY host ORDER BY time) ' + + 'THEN max(v) - lag(max(v)) OVER (PARTITION BY host ORDER BY time) ELSE max(v) END) AS "a"' ); });