在我的数据库中,我有一堆不同城市名称的列表。我试图仅保留此数据库中具有城市名称 = X 的列表并删除所有其他城市。
我正在尝试以下活动记录查询:
@unwanted_cities = Listing.where('city not in (?)', Listing.where('city = ?', "X"));
但我收到这个错误
ActiveRecord::StatementInvalid in Unwanted_cities#index
Showing /Users/AM/Documents/RailsWS/app0521/app/views/unwanted_cities/index.html.erb where line #31 raised:
PG::Error: ERROR: operator does not exist: character varying <> integer
LINE 1: SELECT "listings".* FROM "listings" WHERE (city not in (4,1...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT "listings".* FROM "listings" WHERE (city not in (4,10,13,17,18,19,21,23,26,28,29,31,36,39,46,48,49,52,90,97,101,103,105,108,109,111,115,94,5 ,219..............))
我究竟做错了什么?