diff --git a/public/app/plugins/datasource/influxdb/fsql/sqlUtil.test.ts b/public/app/plugins/datasource/influxdb/fsql/sqlUtil.test.ts index 4864004b8ec..7ca87d9f8ae 100644 --- a/public/app/plugins/datasource/influxdb/fsql/sqlUtil.test.ts +++ b/public/app/plugins/datasource/influxdb/fsql/sqlUtil.test.ts @@ -78,4 +78,29 @@ describe('toRawSql', () => { const result = toRawSql(testQuery); expect(result).toEqual(expected); }); + + it('should not wrap * with quote', () => { + const expected = 'SELECT * FROM "TestValue" WHERE "time" >= $__timeFrom AND "time" <= $__timeTo LIMIT 50'; + const testQuery: SQLQuery = { + refId: 'A', + sql: { + limit: 50, + columns: [ + { + parameters: [ + { + name: '*', + type: QueryEditorExpressionType.FunctionParameter, + }, + ], + type: QueryEditorExpressionType.Function, + }, + ], + }, + dataset: 'iox', + table: 'TestValue', + }; + const result = toRawSql(testQuery); + expect(result).toEqual(expected); + }); }); diff --git a/public/app/plugins/datasource/influxdb/fsql/sqlUtil.ts b/public/app/plugins/datasource/influxdb/fsql/sqlUtil.ts index 41317454a95..8d357fce734 100644 --- a/public/app/plugins/datasource/influxdb/fsql/sqlUtil.ts +++ b/public/app/plugins/datasource/influxdb/fsql/sqlUtil.ts @@ -26,7 +26,10 @@ export function toRawSql({ sql, table }: SQLQuery): string { } // wrapping the column name with quotes - const sc = sql.columns.map((c) => ({ ...c, parameters: c.parameters?.map((p) => ({ ...p, name: `"${p.name}"` })) })); + const sc = sql.columns.map((c) => ({ + ...c, + parameters: c.parameters?.map((p) => ({ ...p, name: formatTableName(p.name) })), + })); rawQuery += createSelectClause(sc); if (table) { @@ -66,6 +69,16 @@ export function toRawSql({ sql, table }: SQLQuery): string { return rawQuery; } +// When the column name is *, do not wrap the column name in double-quotes. +// See: https://github.com/grafana/grafana/issues/88008 +function formatTableName(parameter: string | undefined): string { + if (parameter === '*') { + return parameter; + } + + return `"${parameter}"`; +} + const isLimit = (limit: number | undefined): boolean => limit !== undefined && limit >= 0; // Puts double quotes (") around the identifier if it is necessary.