From 49319fbdea67bb4baa5c8c7275522bb8080cfe9b Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Sat, 18 Aug 2018 13:21:08 +0200 Subject: [PATCH] prefill editor with first metric table --- public/app/plugins/datasource/postgres/meta_query.ts | 2 +- public/app/plugins/datasource/postgres/query_ctrl.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/postgres/meta_query.ts b/public/app/plugins/datasource/postgres/meta_query.ts index 756e612142f..eefe011586d 100644 --- a/public/app/plugins/datasource/postgres/meta_query.ts +++ b/public/app/plugins/datasource/postgres/meta_query.ts @@ -24,7 +24,7 @@ export class PostgresMetaQuery { } findMetricTable() { - // query that returns first table found that has a timestamptz column and a float column + // query that returns first table found that has a timestamp(tz) column and a float column let query = ` SELECT table_name, diff --git a/public/app/plugins/datasource/postgres/query_ctrl.ts b/public/app/plugins/datasource/postgres/query_ctrl.ts index 8bd61a59493..1fc39dc6010 100644 --- a/public/app/plugins/datasource/postgres/query_ctrl.ts +++ b/public/app/plugins/datasource/postgres/query_ctrl.ts @@ -56,6 +56,18 @@ export class PostgresQueryCtrl extends QueryCtrl { this.target.rawSql = 'SELECT 1'; } else { this.target.rawSql = defaultQuery; + this.datasource.metricFindQuery(this.metaBuilder.findMetricTable()).then(result => { + if (result.length > 0) { + this.target.table = result[0].text; + this.tableSegment = uiSegmentSrv.newSegment(this.target.table); + this.target.timeColumn = result[1].text; + this.timeColumnSegment = uiSegmentSrv.newSegment(this.target.timeColumn); + this.target.timeColumnType = 'timestamp'; + this.target.select = [[{ type: 'column', params: [result[2].text] }]]; + this.updateProjection(); + this.panelCtrl.refresh(); + } + }); } }