class Sequel::SQL::Window
A Window
is part of a window function specifying the window over which a window function operates.
Sequel::SQL::Window.new(partition: :col1) # (PARTITION BY col1) Sequel::SQL::Window.new(partition: [:col2, :col3]) # (PARTITION BY col2, col3) Sequel::SQL::Window.new(order: :col4) # (ORDER BY col4) Sequel::SQL::Window.new(order: [:col5, Sequel.desc(:col6)]) # (ORDER BY col5, col6 DESC) Sequel::SQL::Window.new(partition: :col7, frame: :all) # (PARTITION BY col7 ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) Sequel::SQL::Window.new(partition: :col7, frame: :rows) # (PARTITION BY col7 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) Sequel::SQL::Window.new(partition: :col7, frame: {type: :range, start: current}) # (PARTITION BY col7 RANGE CURRENT ROW) Sequel::SQL::Window.new(partition: :col7, frame: {type: :range, start: 1, end: 1}) # (PARTITION BY col7 RANGE BETWEEN 1 PRECEDING AND 1 FOLLOWING) Sequel::SQL::Window.new(partition: :col7, frame: {type: :range, start: 2, end: [1, :preceding]}) # (PARTITION BY col7 RANGE BETWEEN 2 PRECEDING AND 1 PRECEDING) Sequel::SQL::Window.new(partition: :col7, frame: {type: :range, start: 1, end: [2, :following]}) # (PARTITION BY col7 RANGE BETWEEN 1 FOLLOWING AND 2 FOLLOWING) Sequel::SQL::Window.new(partition: :col7, frame: {type: :range, start: :preceding, exclude: :current}) # (PARTITION BY col7 RANGE UNBOUNDED PRECEDING EXCLUDE CURRENT ROW) Sequel::SQL::Window.new(window: :named_window) # you can create a named window with Dataset#window # (named_window)
Attributes
The options for this window. Options currently supported:
- :frame
-
if specified, should be :all, :rows, :range, :groups, a
String
, or aHash
.- :all
-
Always operates over all rows in the partition
- :rows
-
Includes rows in the partition up to and including the current row
- :range, :groups
-
Includes rows in the partition up to and including the current group
String
-
Used as literal
SQL
code, try to avoid Hash
-
Hash
of options for the frame:- :type
-
The type of frame, must be :rows, :range, or :groups (required)
- :start
-
The start of the frame (required). Possible values:
- :end
-
The end of the frame. Can be left out. If present, takes the same values as :start, except that when a
String
,Numeric
, orHash
, it is used as the offset for rows following - :exclude
-
Which rows to exclude. Possible values are :current, :ties, :group :no_others.
- :order
-
order on the column(s) given
- :partition
-
partition/group on the column(s) given
- :window
-
base results on a previously specified named window
Public Class Methods
Set the options to the options given
# File lib/sequel/sql.rb 1992 def initialize(opts=OPTS) 1993 @opts = opts.frozen? ? opts : Hash[opts].freeze 1994 freeze 1995 end