Browse files

Allow :frame option for windows to take a string that is used literally

Previously, the :frame option could just be nil, :all, or :rows.
Those three options covered all cases possible in PostgreSQL 8.4+,
but the SQL standard (and PostgreSQL 9.0) supports many more
possibilities.  In the future, it's possible that better DSL support
will be added, but in the meantime using a string allows you full
control over the window's frame.
  • Loading branch information...
1 parent 6e967a2 commit 2c70fdefefda2b2a75870c60f8338291b0fc0c0b @jeremyevans committed Jun 23, 2010
Showing with 9 additions and 1 deletion.
  1. +2 −0 CHANGELOG
  2. +3 −1 lib/sequel/dataset/sql.rb
  3. +4 −0 spec/core/expression_filters_spec.rb
View
2 CHANGELOG
@@ -1,5 +1,7 @@
=== HEAD
+* Allow :frame option for windows to take a string that is used literally (jeremyevans)
+
* Support transaction isolation levels on PostgreSQL, MySQL, and MSSQL (jeremyevans)
* Support prepared transactions/two-phase commit on PostgreSQL, MySQL, and H2 (jeremyevans)
View
4 lib/sequel/dataset/sql.rb
@@ -442,8 +442,10 @@ def window_sql(opts)
"ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING"
when :rows
"ROWS UNBOUNDED PRECEDING"
+ when String
+ opts[:frame]
else
- raise Error, "invalid window frame clause, should be :all, :rows, or nil"
+ raise Error, "invalid window frame clause, should be :all, :rows, a string, or nil"
end
"(#{[window, partition, order, frame].compact.join(' ')})"
end
View
4 spec/core/expression_filters_spec.rb
@@ -556,6 +556,10 @@ def @d.l(*args, &block)
@d.l{rank(:over, :frame=>:rows){}}.should == 'rank() OVER (ROWS UNBOUNDED PRECEDING)'
end
+ it "should support :frame=>'some string' option for window function calls" do
+ @d.l{rank(:over, :frame=>'RANGE BETWEEN 3 PRECEDING AND CURRENT ROW'){}}.should == 'rank() OVER (RANGE BETWEEN 3 PRECEDING AND CURRENT ROW)'
+ end
+
it "should raise an error if an invalid :frame option is used" do
proc{@d.l{rank(:over, :frame=>:blah){}}}.should raise_error(Sequel::Error)
end

0 comments on commit 2c70fde

Please sign in to comment.