Can't join and select in Sequel — PG::SyntaxError

☆樱花仙子☆ 提交于 2019-12-14 03:23:53

问题


I'm trying to rename a column at join:

    # ...............

    result = DB[:my_items1].join(:my_items2, id: :my_item2_id).
          select([Sequel[:my_items2][:name].as(:my_items_name), 
                  Sequel[:my_items2][:amount].as(:my_item2_amount)
          ])

    # ...............

Exception:

Sequel::DatabaseError - PG::SyntaxError: ERROR:  syntax error at or near "AS"
LINE 1: SELECT ("my_items2"."name" AS "my_item2_name", "...
                                         ^
:

回答1:


Dataset#select takes multiple arguments, not a single array:

result = DB[:my_items1].join(:my_items2, id: :my_item2_id).
      select(Sequel[:my_items2][:name].as(:my_items_name), 
              Sequel[:my_items2][:amount].as(:my_item2_amount)
      )


来源:https://stackoverflow.com/questions/50793928/cant-join-and-select-in-sequel-pgsyntaxerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!