`except': EXCEPT 不支持 (Sequel::InvalidOperation)

Posted

技术标签:

【中文标题】`except\': EXCEPT 不支持 (Sequel::InvalidOperation)【英文标题】:`except': EXCEPT not supported (Sequel::InvalidOperation)`except': EXCEPT 不支持 (Sequel::InvalidOperation) 【发布时间】:2016-01-05 01:43:08 【问题描述】:

我在尝试运行 sinatra 应用程序时遇到错误。我试着用谷歌搜索它,但什么也没出现。如果你们可以就如何解决它或我做错了什么提供任何建议,那将是很大的帮助。

部分代码出错

   def logTownDeltas!(newDate)
        deltas = []

        oldTowns = @db[:towns].filter  data_timestamp < newDate 
        currentTowns = @db[:towns].except(oldTowns)

        destroyedTownIDs = oldTowns.select(:town_id).except(currentTowns.select(:town_id)).collect  |d| d[:town_id] 
        createdTownIDs = currentTowns.select(:town_id).except(oldTowns.select(:town_id)).collect  |c| c[:town_id] 

        alteredTowns = Hash.new
        currentTowns.each  |town|

        

错误

    C:/Ruby22/lib/ruby/gems/2.2.0/gems/sequel-4.29.0/lib/sequel/dataset/query.rb:119:in `except': EXCEPT not supported (Sequel::InvalidOperation)
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:107:in `logTownDeltas!'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:93:in `parseTownData'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:45:in `block (2 levels) in run!'
    from C:/Ruby22/lib/ruby/2.2.0/open-uri.rb:154:in `open_uri'
    from C:/Ruby22/lib/ruby/2.2.0/open-uri.rb:716:in `open'
    from C:/Ruby22/lib/ruby/2.2.0/open-uri.rb:34:in `open'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:44:in `block in run!'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:41:in `each'
    from C:/Users/dakota/Desktop/IllyriadAp/data_syndicator/core.rb:41:in `run!'
    from data_syndicator.rb:17:in `<main>'

插入数据库

 destroyedTownIDs.each  |d|
            t = oldTowns.filter(:town_id => d).first
            @db[:town_deltas].insert(
                :happened_at => newDate,
                :town_id => d,
                :owner_id => t[:owner_id],
                :name => t[:name],
                :population => 0,
                :is_capital => 0,
                :is_alliance_capital => 0)
        


        createdTownIDs.each  |c|
            t = currentTowns.filter(:town_id => c).first
            @db[:town_deltas].insert(
                :happened_at => newDate,
                :town_id => c,
                :owner_id => t[:owner_id],
                :name => t[:name],
                :population => t[:population],
                :is_capital => t[:is_capital],
                :is_alliance_capital => t[:is_alliance_capital])
        

Link to full source just in case

【问题讨论】:

我使用的是mysql数据库 MySql 不支持 EXCEPT 语法。见***.com/questions/16092353/… 是的,我看到,在我现在发布这个之后,我想弄清楚我会用什么来代替 EXCEPT 当我将其更改为开始获取 C:/Ruby22/lib/ruby/gems/2.2.0/gems/sequel-4.29.0/lib/sequel/adapters/mysql.rb 的位置时: 175:in `query': Mysql::Error: Subquery return more than 1 row (Sequel::DatabaseError) 【参考方案1】:

试试这个:

def logTownDeltas!(newDate)
  deltas = []
  currentTowns = @db[:towns].filter  data_timestamp >= newDate 

  destroyedTownIDs = @db[:towns].select(:town_id).filter  data_timestamp < newDate .collect  |d| d[:town_id] 
  createdTownIDs = @db[:towns].select(:town_id).filter  data_timestamp >= newDate .collect  |c| c[:town_id] 

        alteredTowns = Hash.new
        currentTowns.each  |town|

        

【讨论】:

非常感谢您的帮助 在我的下一行代码找到destroyTownIDs 和createdTownIDs 后我遇到了一个问题,它输入数据库只有destroyTownIDs 有0 pop 然后执行createdTownIDs 但现在它为每个城镇创建0 pop 数据那是前一天在数据库中的。我把输入数据的编码放到上面的数据库中

以上是关于`except': EXCEPT 不支持 (Sequel::InvalidOperation)的主要内容,如果未能解决你的问题,请参考以下文章

Python - except不指定异常类别(转)

Python入门教程第54篇 异常处理之try…except…else

phpmyadmin EXCEPT SELECT 不可用

使用'except'进行查询优化

Spark-SQL 是不是支持使用 regex 规范的 Hive Select All Query with except Columns

异常处理