Class: Sequel::SQL::Window

Inherits:
Expression show all
Defined in:
lib/sequel/sql.rb

Overview

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: "RANGE CURRENT ROW")
# (PARTITION BY col7 RANGE CURRENT ROW)

Sequel::SQL::Window.new(window: :named_window) # you can create a named window with Dataset#window
# (named_window)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expression

#==, attr_reader, #clone, #eql?, #hash, inherited, #inspect

Constructor Details

#initialize(opts = OPTS) ⇒ Window

Set the options to the options given



1902
1903
1904
1905
# File 'lib/sequel/sql.rb', line 1902

def initialize(opts=OPTS)
  @opts = opts.frozen? ? opts : Hash[opts].freeze
  freeze
end

Instance Attribute Details

#optsObject (readonly)

The options for this window. Options currently supported:

:frame

if specified, should be :all, :rows, or a String that is used literally. :all always operates over all rows in the partition, while :rows excludes the current row's later peers. The default is to include all previous rows in the partition up to the current row's last peer.

:order

order on the column(s) given

:partition

partition/group on the column(s) given

:window

base results on a previously specified named window



1899
1900
1901
# File 'lib/sequel/sql.rb', line 1899

def opts
  @opts
end