Skip to content

Conversation

aidanharan
Copy link
Contributor

To limit the results in SQL Server we use FETCH NEXT @0 ROWS ONLY instead of LIMIT @0. To use FETCH NEXT an order must be provided.

https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/actions/runs/11104499885/job/30848683699

  1) Failure:
CalculationsTest#test_no_order_by_when_counting_all [/usr/local/bundle/bundler/gems/rails-ebd9beebebe9/activerecord/test/cases/calculations_test.rb:315]:
Expected /ORDER BY/ to not match "EXEC sp_executesql N'SELECT COUNT(*) FROM (SELECT 1 AS one FROM [accounts] ORDER BY [accounts].[id] ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY) subquery_for_count', N'@0 int', @0 = 10".

@aidanharan aidanharan marked this pull request as ready for review September 30, 2024 13:30
@aidanharan aidanharan merged commit e3aba95 into main Sep 30, 2024
4 checks passed
@aidanharan aidanharan deleted the coerce-order-count branch September 30, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant