【发布时间】:2015-11-05 17:35:47
【问题描述】:
我正在尝试根据 Postgres 数组(在 Postgres 9.4 中表示为文本字段)中的项目数来选择一行,并且能够在 Rails 4.2 中选择/分组
我有以下表格:
queryable_id | liked_count | users_who_like_ids
--------------+-------------+--------------------
2376 | 3 | {1,80,78,101, 188}
18771 | 1 | {78,101, 123,125}
1790 | 1 | {78}
2257 | 1 | {78}
比如我想说select and order by user_who_like_ids like
select * from items group by count(users_who_like_ids) where users_who_like_ids include (78,123,125)
我将如何进行此查询? Rails 是否支持这种类型的查询?
编辑 1
这里是 users_who_like_ids
users_who_like_ids | text[] | default '{}'::text[]
编辑 2
看起来有点像这样:
select queryable_id, liked_count, users_who_like_ids from queryables where users_who_like_ids @> ARRAY['1','80'];
但这需要 1 和 80
【问题讨论】:
标签: sql ruby-on-rails postgresql