JSON query when object keys unnamed

Поиск
Список
Период
Сортировка
От Chris Gormley
Тема JSON query when object keys unnamed
Дата
Msg-id D4E712D7-EFF7-437C-AEB8-ED3AB09E2D5F@gmail.com
обсуждение исходный текст
Ответы RE: JSON query when object keys unnamed  ("Aleksey M Boltenkov" <holybolt@rambler.ru>)
Список pgsql-novice
Hi all,
I’m new to this, so I hope someone can help me. I have the following JSON in a data field that I’m trying to separate into its component parts but having difficulty with the unnamed object keys:

{
   “CId” : ”xxx”,
   ”EId” : ”xxx”,
   “MEColl” : [{
         “Key” : “Trans.PLF” ,
         “Value” : “0001”
   }, {
         “Key” : “Trans.BA”,
         “Value” : “8.0”
   }, {
         “Key” : “Trans.TS”,
         “Value” : “2020-05-01T00:00:00”
   }]
   “MId” : “xxx”
}


So the question is, how do I extract each of the 3 x values from the key/value pairs for “MEColl” as they all have the name of “Key” rather than a unique name?


So far, I’ve managed to isolate the first key/value pair using:

SELECT
     data->’MEColl’->0


This returns:

{“Key” : “Trans.PLF” , “Value” : “0001”}


But what I need are the values “Trans.PLF” and “0001” as well as the other values of the other 2 x key/value pairs.

I think I might have to use jsonb_array_elements but can’t seem to get the syntax right.

I know this is simple stuff for the experienced, but struggling despite trying read most of the internet to resolve myself.

Any help greatly appreciated.
Thanks
Chris

В списке pgsql-novice по дате отправления:

Предыдущее
От: Lætitia Avrot
Дата:
Сообщение: Re: How to post a question
Следующее
От: "Aleksey M Boltenkov"
Дата:
Сообщение: RE: JSON query when object keys unnamed