From 8ced29a0e716ef3a7efa166f90282345cd76f8a2 Mon Sep 17 00:00:00 2001 From: Sven Klemm Date: Thu, 16 Aug 2018 11:47:45 +0200 Subject: [PATCH] Don't do value suggestions for numeric and timestamp --- .../plugins/datasource/postgres/meta_query.ts | 1 - .../plugins/datasource/postgres/query_ctrl.ts | 25 ++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/postgres/meta_query.ts b/public/app/plugins/datasource/postgres/meta_query.ts index 414bbe654ef..ed1226d6b30 100644 --- a/public/app/plugins/datasource/postgres/meta_query.ts +++ b/public/app/plugins/datasource/postgres/meta_query.ts @@ -143,7 +143,6 @@ WHERE ) s WHERE EXISTS (SELECT 1 FROM information_schema.schemata WHERE schema_name = s.schema) ) -LIMIT 1 `; query += ' AND table_name = ' + this.quoteIdentAsLiteral(this.target.table); query += ' AND column_name = ' + this.quoteIdentAsLiteral(column); diff --git a/public/app/plugins/datasource/postgres/query_ctrl.ts b/public/app/plugins/datasource/postgres/query_ctrl.ts index 2e0f22792af..be2ec175b26 100644 --- a/public/app/plugins/datasource/postgres/query_ctrl.ts +++ b/public/app/plugins/datasource/postgres/query_ctrl.ts @@ -474,10 +474,22 @@ export class PostgresQueryCtrl extends QueryCtrl { .then(this.transformToSegments({})) .catch(this.handleQueryError.bind(this)); case 'right': - return this.datasource - .metricFindQuery(this.metaBuilder.buildValueQuery(part.params[0])) - .then(this.transformToSegments({ addTemplateVars: true, templateQuoter: this.queryModel.quoteLiteral })) - .catch(this.handleQueryError.bind(this)); + if (['int4', 'int8', 'float4', 'float8', 'timestamp', 'timestamptz'].indexOf(part.datatype) > -1) { + // don't do value lookups for numerical fields + return this.$q.when([]); + } else { + return this.datasource + .metricFindQuery(this.metaBuilder.buildValueQuery(part.params[0])) + .then( + this.transformToSegments({ + addTemplateVars: true, + templateQuoter: (v: string) => { + return this.queryModel.quoteLiteral(v); + }, + }) + ) + .catch(this.handleQueryError.bind(this)); + } case 'op': return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '<', '<=', '>', '>=', 'IN', 'NOT IN'])); default: @@ -485,6 +497,11 @@ export class PostgresQueryCtrl extends QueryCtrl { } } case 'part-param-changed': { + this.datasource.metricFindQuery(this.metaBuilder.buildDatatypeQuery(part.params[0])).then((d: any) => { + if (d.length === 1) { + part.datatype = d[0].text; + } + }); this.panelCtrl.refresh(); break; }