diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index b98d0dbb..fd860318 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -118,7 +118,8 @@ const gridResolution = ctx => `(${256*0.00028/ctx.res}*!scale_denominator!)::dou const aggregationQueryTemplates = { 'centroid': ctx => ` - WITH _cdb_params AS ( + WITH + _cdb_params AS ( SELECT ${gridResolution(ctx)} AS res, !bbox! AS bbox @@ -142,7 +143,8 @@ const aggregationQueryTemplates = { `, 'point-grid': ctx => ` - WITH _cdb_params AS ( + WITH + _cdb_params AS ( SELECT ${gridResolution(ctx)} AS res, !bbox! AS bbox @@ -165,11 +167,13 @@ const aggregationQueryTemplates = { `, 'point-sample': ctx => ` - WITH _cdb_params AS ( + WITH + _cdb_params AS ( SELECT ${gridResolution(ctx)} AS res, !bbox! AS bbox - ), _cdb_clusters AS ( + ), + _cdb_clusters AS ( SELECT MIN(cartodb_id) AS cartodb_id ${dimensionDefs(ctx)} @@ -180,7 +184,8 @@ const aggregationQueryTemplates = { Floor(ST_X(_cdb_query.the_geom_webmercator)/_cdb_params.res), Floor(ST_Y(_cdb_query.the_geom_webmercator)/_cdb_params.res) ${dimensionNames(ctx)} - ) SELECT + ) + SELECT _cdb_clusters.cartodb_id, the_geom, the_geom_webmercator ${dimensionNames(ctx)} @@ -191,11 +196,13 @@ const aggregationQueryTemplates = { `, 'full-sample': ctx => ` - WITH _cdb_params AS ( + WITH + _cdb_params AS ( SELECT ${gridResolution(ctx)} AS res, !bbox! AS bbox - ), _cdb_clusters AS ( + ), + _cdb_clusters AS ( SELECT MIN(cartodb_id) AS cartodb_id ${dimensionDefs(ctx)}