add regex operators

pull/11081/head
Sven Klemm 7 years ago
parent 046ee8efd8
commit b7c7030a46
  1. 8
      public/app/plugins/datasource/postgres/query_builder.ts
  2. 18
      public/app/plugins/datasource/postgres/query_ctrl.ts

@ -47,4 +47,12 @@ export class PostgresQueryBuilder {
return query;
}
buildDatatypeQuery(column: string) {
var query = "SELECT data_type FROM information_schema.columns WHERE ";
query += " table_schema = " + this.queryModel.quoteLiteral(this.target.schema);
query += " AND table_name = " + this.queryModel.quoteLiteral(this.target.table);
query += " AND column_name = " + this.queryModel.quoteLiteral(column);
return query;
}
}

@ -266,14 +266,28 @@ export class PostgresQueryCtrl extends QueryCtrl {
}
getWhereSegments(segment, index) {
var query, addTemplateVars;
if (segment.type === 'condition') {
return this.$q.when([this.uiSegmentSrv.newSegment('AND'), this.uiSegmentSrv.newSegment('OR')]);
}
if (segment.type === 'operator') {
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '<>', '<', '>']));
var columnName = this.whereSegments[index - 1].value;
query = this.queryBuilder.buildDatatypeQuery(columnName);
return this.datasource.metricFindQuery(query)
.then(results => {
var datatype = results[0].text;
switch (datatype) {
case "text":
case "character varying":
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '~', '~*','!~','!~*','IN']));
default:
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '<', '<=', '>', '>=']));
}
})
.catch(this.handleQueryError.bind(this));
}
var query, addTemplateVars;
if (segment.type === 'key' || segment.type === 'plus-button') {
query = this.queryBuilder.buildColumnQuery();

Loading…
Cancel
Save