diff --git a/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js b/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js index d8b01837..b55ead8c 100644 --- a/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js +++ b/lib/cartodb/backends/layer-stats/mapnik-layer-stats.js @@ -137,7 +137,7 @@ function _sample(ctx) { const limit = Math.ceil(requestedRows * 1.5); const columns = ctx.metaOptions.sample.include_columns; - const sqlMaxMin = _getSQL(ctx, sql => queryUtils.getMaxMinColumnQuery(sql)); + const sqlMaxMin = _getSQL(ctx, sql => queryUtils.getMaxMinSpanColumnQuery(sql)); return queryUtils.queryPromise(ctx.dbConnection, sqlMaxMin) .then(maxMinRes => { const { min_id: min, id_span: span } = maxMinRes.rows[0]; diff --git a/lib/cartodb/utils/query-utils.js b/lib/cartodb/utils/query-utils.js index a5bb4482..e288cb32 100644 --- a/lib/cartodb/utils/query-utils.js +++ b/lib/cartodb/utils/query-utils.js @@ -150,13 +150,13 @@ function simpleQueryTable(sql) { return false; } -module.exports.getMaxMinColumnQuery = function (query, column = 'cartodb_id') { +module.exports.getMaxMinSpanColumnQuery = function (query, column = 'cartodb_id') { return ` SELECT min(${column}) AS min_id, max(${column}) AS max_id, (max(${column}) - min(${column})) AS id_span - FROM (${substituteDummyTokens(query)}) _cdb_metadata_max_min; + FROM (${substituteDummyTokens(query)}) _cdb_metadata_max_min_span; `; };