diff --git a/lib/cartodb/models/dataview/histogram.js b/lib/cartodb/models/dataview/histogram.js index 4499dd6c..8d624163 100644 --- a/lib/cartodb/models/dataview/histogram.js +++ b/lib/cartodb/models/dataview/histogram.js @@ -159,11 +159,15 @@ var dateOverrideBasicsQueryTpl = dot.template([ ' max({{=it._end}}) AS max_val,', ' min({{=it._start}}) AS min_val,', ' avg(date_part(\'epoch\', {{=it._column}})) AS avg_val,', - ' min(date_trunc(', - ' \'{{=it._aggregation}}\',', - ' TO_TIMESTAMP({{=it._start}})::timestamp AT TIME ZONE \'{{=it._timezone}}\'', - ' )) AS start_date,', - ' max(TO_TIMESTAMP({{=it._end}})::timestamp AT TIME ZONE \'{{=it._timezone}}\') AS end_date,', + ' min(', + ' date_trunc(', + ' \'{{=it._aggregation}}\',', + ' TO_TIMESTAMP({{=it._start}})::timestamp AT TIME ZONE \'{{=it._timezone}}\'', + ' )', + ' ) AS start_date,', + ' max(', + ' TO_TIMESTAMP({{=it._end}})::timestamp AT TIME ZONE \'{{=it._timezone}}\'', + ' ) AS end_date,', ' count(1) AS total_rows', ' FROM ({{=it._query}}) _cdb_basics', ')' @@ -177,15 +181,11 @@ var dateBinsQueryTpl = dot.template([ ' FROM (', ' SELECT', ' ARRAY(', - ' {{?it._aggregation==="quarter"}}', - ' SELECT GENERATE_SERIES(start_date::timestamptz, end_date::timestamptz, \'3 month\'::interval)', - ' {{??}}', ' SELECT GENERATE_SERIES(', ' start_date::timestamptz,', ' end_date::timestamptz,', - ' \'1 {{=it._aggregation}}\'::interval', + ' {{?it._aggregation==="quarter"}}\'3 month\'{{??}}\'1 {{=it._aggregation}}\'{{?}}::interval', ' )', - ' {{?}}', ' ) AS bins_array', ' FROM basics', ' ) _cdb_bins_array', @@ -207,10 +207,14 @@ var dateHistogramQueryTpl = dot.template([ ' bins_number', ' )) - 1', ' END AS bin,', - ' min(date_part(', - ' \'epoch\', ', - ' date_trunc(\'{{=it._aggregation}}\', {{=it._column}}::timestamptz', - ' ) AT TIME ZONE \'{{=it._timezone}}\'))::numeric AS timestamp,', + ' min(', + ' date_part(', + ' \'epoch\', ', + ' date_trunc(', + ' \'{{=it._aggregation}}\', {{=it._column}}::timestamptz', + ' ) AT TIME ZONE \'{{=it._timezone}}\'', + ' )', + ' )::numeric AS timestamp,', ' min(date_part(\'epoch\', {{=it._column}}))::numeric AS min,', ' max(date_part(\'epoch\', {{=it._column}}))::numeric AS max,', ' avg(date_part(\'epoch\', {{=it._column}}))::numeric AS avg,',