1. 程式人生 > >【Rails】PostgreSQL中巢狀json查詢

【Rails】PostgreSQL中巢狀json查詢

備忘:工作記錄。

# attr_json:{"ext": {"conditions": {"appId": "168","templateSettings": {"is_show": true,"pages": ["pages/1/index", "pages/2/index"]}}}}

Program::Data.find_by_sql(
    "select * from program_data where 
        attr_json::json->'ext'->'conditions'->>'templateSettings' 
            is not null")
::json | json格式;
->     | 下級key (仍為json)
->>    | 下級key (轉為text?varchar?)
再做條件對比。