jsonb postgres获取选择数组行以注释子json

时间:2019-03-13 16:39:19

标签: json postgresql jsonb

嗨,我有一个具有这种结构的json

enter image description here

@Autowired

所以我试图用数组中的number_week和session来检索所有星期,所以我有这个查询

"units":[   "weeks": [  
   {  
      "sessions":[  
         {  
            "subject":"",
            "activities":[  
               {  
                  "modality":"",
                  "description":"",
                  "type_activity":"",
                  "label_description":""
               }
            ],
            "number_session":1
         }
      ],
      "number_week":"1"
   },
   {  
      "sessions":[  
         {  
            "subject":"",
            "activities":[  
               {  
                  "modality":"",
                  "description":"",
                  "type_activity":"",
                  "label_description":""
               }
            ],
            "number_session":1
         }
      ],
      "number_week":"2"
   },
   {  
      "sessions":[  
         {  
            "subject":"",
            "activities":[  
               {  
                  "modality":"",
                  "description":"",
                  "type_activity":"",
                  "label_description":""
               }
            ],
            "number_session":1
         }
      ],
      "number_week":"3"
   },
   {  
      "sessions":[  
         {  
            "subject":"",
            "activities":[  
               {  
                  "modality":"",
                  "description":"",
                  "type_activity":"",
                  "label_description":""
               }
            ],
            "number_session":1
         }
      ],
      "number_week":"4"
   }
]]

但不起作用。如何检索值的正确性,我有空值,但是我在表中找到了值。

我希望得到这个结果

number_week

select value->'weeks'->'number_week' as title
 from  syllabus_programs
 cross join jsonb_array_elements(program_json->'units')

 where id =12;

如果我只能访问value->'weeks'返回带有键和值的json,但是我不能访问该值。

0 个答案:

没有答案