0

I have a table from which I want to fetch two fields of which one is JSONB with JSONB values in to new columns.

SELECT ID, ATTRIBS from EMPLOYEE;

This returns me the output as follows.

   id  |                attribs
------------------------------------------------------------------------------------
 EM001 | {"Education": "C.A.", "Contact No": "6655448822", "Relative Name": "Ganga"}
 EM002 | {"Education": "M.E.", "Contact No": "6542349992", "Relative Name": "Yamuna"}

I would like to have the output as follows

   id  | Education | Contact No | Relative Name
-----------------------------------------------
 EM001 | C.A.      | 6655448822 | Ganga
 EM002 | M.E.      | 6542349992 | Yamuna

Any suggestions how I can do this?

1 Answer 1

1

Use the ->> operator to extract values based on a key:

select id, 
       attribs ->> 'Education' as education,
       attribs ->> 'Contact No' as "Contact No",
       attribs ->> 'Relative Name' as "Relative Name"
from the_table
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.