diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 4f7060c5..4ae3bc33 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -117,17 +117,19 @@ const dimensionNames = (ctx, table) => { let dimensions = aggregateDimensions(ctx); if (table) { return sep(Object.keys(dimensions).map( - dimension_name => `${table}.${dimension_name}` + dimension_name => `${table}."${dimension_name}"` )); } - return sep(Object.keys(dimensions)); + return sep(Object.keys(dimensions).map(dimension_name => { + return `"${dimension_name}"`; + })); }; const dimensionDefs = ctx => { let dimensions = aggregateDimensions(ctx); return sep(Object.keys(dimensions).map(dimension_name => { const expression = dimensions[dimension_name]; - return `${expression} AS ${dimension_name}`; + return `"${expression}" AS "${dimension_name}"`; })); };