在尝试根据子查询的结果排序数据集时,我遇到了一个奇怪的问题。它工作正常,直到我尝试添加带偏移的限制,然后我得到一个错误,说排序列名称无效。这是一个显示问题的调试器会话(这是一个有点愚蠢的查询,我只是想尽可能地简化真正的查询,同时仍然得到错误)。
irb(main):009:0> ds = DB[:competency].select(:competencyname)
=> #<Sequel::TinyTDS::Dataset: "SELECT [COMPETENCYNAME] FROM [COMPETENCY]">
irb(main):010:0> ds = ds.select_more(Sequel.as Mssql::CompetencyRating.select(:rating).limit(1), :manager_rating ) => #<Sequel::TinyTDS::Dataset: "SELECT [COMPETENCYNAME], (SELECT TOP (1) [RATING] FROM [COMPETENCYRATING]) AS [MANAGER_RATING] FROM [COMPETENCY]">
irb(main):011:0> ds.count
=> 795
irb(main):012:0> ds = ds.limit(10)
=> #<Sequel::TinyTDS::Dataset: "SELECT TOP (10) [COMPETENCYNAME], (SELECT TOP (1) [RATING] FROM [COMPETENCYRATING]) AS [MANAGER_RATING] FROM [COMPETENCY]">
irb(main):013:0> ds.count => 10
irb(main):015:0> ds = ds.limit(10,2)
=> #<Sequel::TinyTDS::Dataset: "SELECT TOP (10) [COMPETENCYNAME], [MANAGER_RATING] FROM (SELECT [COMPETENCYNAME], (SELECT TOP (1) [RATING] FROM [COMPETENCYRATING]) AS [MANAGER_RATING], ROW_NUMBER() OVER (ORDER BY [COMPETENCYNAME], [MANAGER_RATING]) AS [X_SEQUEL_ROW_NUMBER_X] FROM [COMPETENCY]) AS [T1] WHERE ([X_SEQUEL_ROW_NUMBER_X] > 2) ORDER BY [X_SEQUEL_ROW_NUMBER_X]">
irb(main):016:0> ds.count
Sequel::DatabaseError: TinyTds::Error: Invalid column name 'MANAGER_RATING'.
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/adapters/tinytds.rb:233:in `fields'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/adapters/tinytds.rb:233:in `block in fetch_rows'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/adapters/tinytds.rb:63:in `block in execute'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/database/connecting.rb:229:in `block in synchroni
ze'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/connection_pool/sharded_threaded.rb:128:in `hold'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/database/connecting.rb:229:in `synchronize'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/adapters/tinytds.rb:32:in `execute'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:793:in `execute'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/adapters/tinytds.rb:232:in `fetch_rows'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:143:in `each'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:583:in `single_record'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:591:in `single_value'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:250:in `get'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/sequel-4.3.0/lib/sequel/dataset/actions.rb:107:in `count'
from (irb):16
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/railties-3.2.13/lib/rails/commands/console.rb:47:in `start'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/railties-3.2.13/lib/rails/commands/console.rb:8:in `start'
from /home/tlittle/.rvm/gems/ruby-1.9.3-p327@tms_mobile/gems/railties-3.2.13/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):017:0>
对我来说似乎是一个错误,但我很高兴发现我只是愚蠢。知道出了什么问题吗?
我正在使用续集4.3.0和tiny_tds 0.5.1。
答案 0 :(得分:1)
Sequel-talk Google小组回答:https://groups.google.com/forum/#!topic/sequel-talk/FcGzky8qFiA