Ruby on rails Rails Postgres-Jsonb列查询

Ruby on rails Rails Postgres-Jsonb列查询,ruby-on-rails,ruby,postgresql,Ruby On Rails,Ruby,Postgresql,我有一个Bundle选项卡,其中jsonb列名为“available_quantity”。其中将包含样本值 [{“面额”:“100”,“数量”:“20”},{“面额”:“1000”,“数量”:“19”}] 现在,我想查询数量小于50的所有记录 我试过这个问题 Bundle.where(((可用数量->'quantity')::数值>“数量”)::数值您可以共享该表的架构及其数据示例吗? Bundle.select("*").from(Bundle.select("*, jsonb_array_

我有一个Bundle选项卡,其中jsonb列名为“available_quantity”。其中将包含样本值

[{“面额”:“100”,“数量”:“20”},{“面额”:“1000”,“数量”:“19”}]

现在,我想查询数量小于50的所有记录

我试过这个问题

Bundle.where(((可用数量->'quantity')::数值<50)

但这种回归关系是空的

我该怎么做

模式 示例数据:

id: 2586, project_id: 3, item_type: "GiftCard", item_id: 659, status: 
"activated", created_at: "2020-05-18 09:38:54", updated_at: "2020-05- 
28 13:25:29", denomination_quantity: {"100"=>200, "1000"=>200}, 
deleted_at: nil, available_quantity: [{"quantity"=>16, 
"denomination"=>"100"}, {"quantity"=>20, "denomination"=>1000}]

希望我们在这里使用子查询

 Bundle.select("*").from(Bundle.select("*, jsonb_array_elements(available_quantity) as aq")).where("(aq ->> 'quantity')::numeric <= 50").distinct

Bundle.select(“*”)。从(Bundle.select(“*,jsonb_数组_元素(可用数量)为aq”))。其中(“((aq->>“数量”)::数值您可以共享该表的架构及其数据示例吗?
 Bundle.select("*").from(Bundle.select("*, jsonb_array_elements(available_quantity) as aq")).where("(aq ->> 'quantity')::numeric <= 50").distinct