Median for ActiveRecord
PostgreSQL only, as MySQL only supports aggregate user-defined functions in C and C++, and SQLite only supports them in C
Works with grouping, too.
Add this line to your application’s Gemfile:
And create a migration to add the
median function to the database.
rails g migration create_median_function
def up ActiveMedian.create_function end def down ActiveMedian.drop_function end
Rails can’t store functions in
schema.rb, so add to your
Rake::Task["db:schema:load"].enhance do ActiveMedian.create_function end
Or change the dump format to
config.active_record.schema_format = :sql
Everyone is encouraged to help improve this project. Here are a few ways you can help: