Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Arel should use TOP in updates with a limit on SQL Server

#6280

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.

Reported by Brian Dunn · January 12th, 2011 @ 05:06 AM

State: stale
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Brian Dunn
  2. Brian Dunn
  3. Joseph Holsten
    Joseph Holsten
    • Tag changed from limit rails3 arel, sqlserver to activerecord, arel, limit, patch, rails3, sqlserver

    January 12th, 2011 @ 04:33 PM

  4. rails
    rails
    • 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.

    April 13th, 2011 @ 01:00 AM

  5. rails
    rails
    • State changed from open to stale

    April 13th, 2011 @ 01:00 AM

  6. Brian Dunn