Module: Timescaledb::Rails::Model::Hyperfunctions

Included in:
ClassMethods
Defined in:
lib/timescaledb/rails/model/hyperfunctions.rb

Overview

:nodoc:

Constant Summary collapse

TIME_BUCKET_ALIAS =
'time_bucket'

Instance Method Summary collapse

Instance Method Details

#time_bucket(interval, target_column = nil) ⇒ ActiveRecord::Relation<ActiveRecord::Base>

Returns:



13
14
15
16
17
18
19
20
# File 'lib/timescaledb/rails/model/hyperfunctions.rb', line 13

def time_bucket(interval, target_column = nil)
  target_column ||= hypertable_time_column_name

  select("time_bucket('#{format_interval_value(interval)}', #{target_column}) as #{TIME_BUCKET_ALIAS}")
    .group(TIME_BUCKET_ALIAS)
    .order(TIME_BUCKET_ALIAS)
    .extending(AggregateFunctions)
end