lib/groupdate/adapters/postgresql_adapter.rb in groupdate-5.2.4 vs lib/groupdate/adapters/postgresql_adapter.rb in groupdate-6.0.0
- old
+ new
@@ -19,19 +19,21 @@
when :day_of_year
["EXTRACT(DOY FROM #{day_start_column})::integer", time_zone, day_start_interval]
when :month_of_year
["EXTRACT(MONTH FROM #{day_start_column})::integer", time_zone, day_start_interval]
when :week
- ["(DATE_TRUNC('day', #{day_start_column} - INTERVAL '1 day' * ((? + EXTRACT(DOW FROM #{day_start_column})::integer) % 7)) + INTERVAL ?) AT TIME ZONE ?", time_zone, day_start_interval, 13 - week_start, time_zone, day_start_interval, day_start_interval, time_zone]
+ ["(DATE_TRUNC('day', #{day_start_column} - INTERVAL '1 day' * ((? + EXTRACT(DOW FROM #{day_start_column})::integer) % 7)) + INTERVAL ?)::date", time_zone, day_start_interval, 13 - week_start, time_zone, day_start_interval, day_start_interval]
when :custom
- ["TO_TIMESTAMP(FLOOR(EXTRACT(EPOCH FROM #{column}::timestamptz) / ?) * ?)", n_seconds, n_seconds]
- else
- if day_start == 0
- # prettier
- ["DATE_TRUNC(?, #{day_start_column}) AT TIME ZONE ?", period, time_zone, day_start_interval, time_zone]
+ if @relation.connection.adapter_name == "Redshift"
+ ["TIMESTAMP 'epoch' + (FLOOR(EXTRACT(EPOCH FROM #{column}::timestamp) / ?) * ?) * INTERVAL '1 second'", n_seconds, n_seconds]
else
- ["(DATE_TRUNC(?, #{day_start_column}) + INTERVAL ?) AT TIME ZONE ?", period, time_zone, day_start_interval, day_start_interval, time_zone]
+ ["TO_TIMESTAMP(FLOOR(EXTRACT(EPOCH FROM #{column}::timestamptz) / ?) * ?)", n_seconds, n_seconds]
end
+ when :day, :month, :quarter, :year
+ ["DATE_TRUNC(?, #{day_start_column})::date", period, time_zone, day_start_interval]
+ else
+ # day start is always 0 for seconds, minute, hour
+ ["DATE_TRUNC(?, #{day_start_column}) AT TIME ZONE ?", period, time_zone, day_start_interval, time_zone]
end
clean_group_clause(@relation.send(:sanitize_sql_array, query))
end