Postgres JSON data type Rails query

前端 未结 3 1945
孤城傲影
孤城傲影 2020-11-28 19:40

I am using Postgres\' json data type but want to do a query/ordering with data that is nested within the json.

I want to order or query with .where on the json data

3条回答
  •  盖世英雄少女心
    2020-11-28 20:01

    Your question doesn't seem to correspond to the data you've shown, but if your table is named users and data is a field in that table with JSON like {count:123}, then the query

    SELECT * WHERE data->'count' > 500 FROM users

    will work. Take a look at your database schema to make sure you understand the layout and check that the query works before complicating it with Rails conventions.

提交回复
热议问题