Permalink
Browse files

Merge pull request #69 from thedarkone/oracle-order-by-update

Oracle does not allow ORDER BY/LIMIT in UPDATE queries
  • Loading branch information...
2 parents c750aef + 75a78b3 commit 472c8c709c00a28091e723b095d8fbc23bf8a583 @tenderlove tenderlove committed Jul 26, 2011
Showing with 12 additions and 0 deletions.
  1. +12 −0 lib/arel/visitors/oracle.rb
View
12 lib/arel/visitors/oracle.rb
@@ -65,6 +65,18 @@ def visit_Arel_Nodes_Except o
"( #{visit o.left} MINUS #{visit o.right} )"
end
+ def visit_Arel_Nodes_UpdateStatement o
+ # Oracle does not allow ORDER BY/LIMIT in UPDATEs.
+ if o.orders.any? && o.limit.nil?
+ # However, there is no harm in silently eating the ORDER BY clause if no LIMIT has been provided,
+ # otherwise let the user deal with the error
+ o = o.dup
+ o.orders = []
+ end
+
+ super
+ end
+
###
# Hacks for the order clauses specific to Oracle
def order_hacks o

0 comments on commit 472c8c7

Please sign in to comment.