This project is archived and is in readonly mode.
Arel should use TOP in updates with a limit on SQL Server
Reported by Brian Dunn | January 12th, 2011 @ 05:06 AM
When connected to SQL Server, with a Gemfile that says this
gem 'arel', :git => 'git://github.com/rails/arel.git'
Doing this
User.order(:id).limit(1).update_all("name='brian'")
Will throw an exception like this
ActiveRecord::StatementInvalid: TinyTds::Error: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.: UPDATE [users] SET name='brian' WHERE [users].[id] IN (SELECT [users].[id] FROM [users] ORDER BY id )
Also this
User.limit(1).update_all("name='brian'")
Will silently fail to limit the number of records updated.
Comments and changes to this ticket
-
Brian Dunn January 12th, 2011 @ 05:07 AM
- no changes were found...
-
Brian Dunn January 12th, 2011 @ 05:27 AM
Added bonus: that patch causes this test to pass when using https://github.com/rails-sqlserver/activerecord-sqlserver-adapter.git
https://github.com/rails/rails/blob/v3.0.3/activerecord/test/cases/...
-
Joseph Holsten January 12th, 2011 @ 04:33 PM
- Tag changed from limit rails3 arel, sqlserver to activerecord, arel, limit, patch, rails3, sqlserver
-
rails April 13th, 2011 @ 01:00 AM
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails April 13th, 2011 @ 01:00 AM
- State changed from open to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>