无法在续集中加入和选择 - PG :: SyntaxError

时间:2018-06-11 09:01:10

标签: sql ruby database postgresql sequel

我正在尝试重命名连接时的列:

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

    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)
          ])

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

例外:

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

1 个答案:

答案 0 :(得分:3)

Dataset #select采用多个参数,而不是单个数组:

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)
      )