diff --git a/public/app/plugins/datasource/influxdb/query_builder.ts b/public/app/plugins/datasource/influxdb/query_builder.ts index ba044d436b6..2f148799a99 100644 --- a/public/app/plugins/datasource/influxdb/query_builder.ts +++ b/public/app/plugins/datasource/influxdb/query_builder.ts @@ -19,8 +19,9 @@ function renderTagCondition(tag: { operator: any; value: string; condition: any; } } - // quote value unless regex or number, or if empty-string - if (value === '' || (operator !== '=~' && operator !== '!~' && isNaN(+value))) { + // quote value unless regex or empty-string + // Influx versions before 0.13 had inconsistent requirements on if (numeric) tags are quoted or not. + if (value === '' || (operator !== '=~' && operator !== '!~')) { value = "'" + value.replace(/\\/g, '\\\\').replace(/\'/g, "\\'") + "'"; } diff --git a/public/app/plugins/datasource/influxdb/specs/query_builder.test.ts b/public/app/plugins/datasource/influxdb/specs/query_builder.test.ts index 9c989f671b6..07be475e028 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_builder.test.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_builder.test.ts @@ -166,7 +166,7 @@ describe('InfluxQueryBuilder', () => { undefined ); const query = builder.buildExploreQuery('MEASUREMENTS'); - expect(query).toBe(`SHOW MEASUREMENTS WHERE "app" == 42 LIMIT 100`); + expect(query).toBe(`SHOW MEASUREMENTS WHERE "app" == '42' LIMIT 100`); }); it('should handle tag-value=number-ish getting tag-keys', () => { @@ -175,7 +175,7 @@ describe('InfluxQueryBuilder', () => { undefined ); const query = builder.buildExploreQuery('TAG_KEYS'); - expect(query).toBe(`SHOW TAG KEYS WHERE "app" == 42`); + expect(query).toBe(`SHOW TAG KEYS WHERE "app" == '42'`); }); it('should handle tag-value-contains-backslash-character getting tag-keys', () => {