ActiveRecordExtended v1.3.0 Release Notes
Release Date: 2019-09-09 // over 4 years ago-
➕ Add Postgres Window Functions to ActiveRecord querying level.
- introduces two new methods that are used in conjunction:
.define_window
&.select_window
###define_window/1
&&partition_by/2
Defines one or many windows that will be place at the bottom of your query. This will also require you to define a partition via.parition_by(:column)/2
. partition_by/2
arguments:- column name being partitioned
order_by
Processes how the window should be orders
- introduces two new methods that are used in conjunction:
Example:
User.define_window(:w).partition_by(:name, order_by: :join_date)
select_window/4
Arguments:
- 📄 Window Function Name
- Function's arguments *optional*
over:
- The window name given when constructing
.define_window
- The window name given when constructing
as:
*optional*- Alias name to give the final result
Overall Examples:
User.define_window(:w).partition_by(:name).select_window(:row_number, over: :w, as: :r_id)
User.define_window(:w).partition_by(:name).select_window(:first_value, :id, over: :w, as: :first_id)