diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index f55c9e75..55bdf7f0 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -89,7 +89,7 @@ const SUPPORTED_AGGREGATE_FUNCTIONS = { sql: (column_name, params) => `max(${params.aggregated_column || column_name})` }, 'mode': { - sql: (column_name, params) => `_cdb_mode(${params.aggregated_column || column_name})` + sql: (column_name, params) => `mode() WITHIN GROUP (ORDER BY ${params.aggregated_column || column_name})` } }; diff --git a/test/acceptance/aggregation.js b/test/acceptance/aggregation.js index 48232614..82a3da5a 100644 --- a/test/acceptance/aggregation.js +++ b/test/acceptance/aggregation.js @@ -2354,7 +2354,7 @@ describe('aggregation', function () { threshold: 1, columns: { value: { - aggregate_function: 'sum', + aggregate_function: 'mode', aggregated_column: 'value' } }, @@ -2400,7 +2400,7 @@ describe('aggregation', function () { threshold: 1, columns: { value: { - aggregate_function: 'sum', + aggregate_function: 'mode', aggregated_column: 'value' } },