Permalink
Browse files

Fix ordering of UNION, INTERSECT, and EXCEPT statements (Fixes #253)

Before, the UNION, INTERESECT, and EXCEPT statements came after
ORDER BY by default, this commit moves them before ORDER BY.  Some
of the adapters were changed, but not all.  If you use UNION,
INTERSECT, or EXCEPT, please test with your database to make sure it
still works.
  • Loading branch information...
1 parent cde6c93 commit c790367020280e1495e31c5a53fe380f48980b19 @jeremyevans committed Dec 1, 2008
Showing with 4 additions and 2 deletions.
  1. +2 −0 CHANGELOG
  2. +1 −1 lib/sequel_core/adapters/shared/postgres.rb
  3. +1 −1 lib/sequel_core/dataset/sql.rb
View
@@ -1,5 +1,7 @@
=== HEAD
+* Fix ordering of UNION, INTERSECT, and EXCEPT statements (jeremyevans) (#253)
+
* Support aliasing subselects in the Oracle adapter (jeremyevans)
* Add a subadapter for the Progress RDBMS to the ODBC adapter (:db_type=>'progress') (groveriffic) (#251)
@@ -394,7 +394,7 @@ module DatasetMethods
QUERY_PLAN = 'QUERY PLAN'.to_sym
ROW_EXCLUSIVE = 'ROW EXCLUSIVE'.freeze
ROW_SHARE = 'ROW SHARE'.freeze
- SELECT_CLAUSE_ORDER = %w'distinct columns from join where group having order limit union intersect except lock'.freeze
+ SELECT_CLAUSE_ORDER = %w'distinct columns from join where group having intersect union except order limit lock'.freeze
SHARE = 'SHARE'.freeze
SHARE_ROW_EXCLUSIVE = 'SHARE ROW EXCLUSIVE'.freeze
SHARE_UPDATE_EXCLUSIVE = 'SHARE UPDATE EXCLUSIVE'.freeze
@@ -12,7 +12,7 @@ class Dataset
NULL = "NULL".freeze
QUESTION_MARK = '?'.freeze
STOCK_COUNT_OPTS = {:select => ["COUNT(*)".lit], :order => nil}.freeze
- SELECT_CLAUSE_ORDER = %w'distinct columns from join where group having order limit union intersect except'.freeze
+ SELECT_CLAUSE_ORDER = %w'distinct columns from join where group having intersect union except order limit'.freeze
TIMESTAMP_FORMAT = "TIMESTAMP '%Y-%m-%d %H:%M:%S'".freeze
TWO_ARITY_OPERATORS = ::Sequel::SQL::ComplexExpression::TWO_ARITY_OPERATORS
WILDCARD = '*'.freeze

0 comments on commit c790367

Please sign in to comment.