Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
163 views
in Technique[技术] by (71.8m points)

jason - Not able to extract data element from the JSONB field

I am using PGADMIN4 to extract data elements from JSONB field called "resource" (postgress database). Here is the example of JSONB:

  "resource": {
        "type": [
            {
                "text": "assessment",
                "coding": [
                    {
                        "code": "000000000",
                        "system": "   ",
                        "display": "assessment"
                    },
                    {
                        "code": "111111111",
                        "system": "   ",
                        "display": "test"
                    }
                ]
            }
        ]

I used the following code to extract text, code and display. I am able to extract the text correctly by code and display are null. Can someone please help.

select jsonb_array_elements(a.resource -> 'resource' -> 'type') ->> 'text' as encounter_text,
jsonb_array_elements(a.resource -> 'resource' -> 'type' -> 'coding') ->> 'code' as code,
jsonb_array_elements(a.resource -> 'resource' -> 'type' -> 'coding') ->> 'display' as display 
from data a
question from:https://stackoverflow.com/questions/65854580/not-able-to-extract-data-element-from-the-jsonb-field

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...