0

I have a multiple jsonb strings in a table that where created by a third party app. I want to be able to separate the content into individual rows. A string looks like this:

[[ "Plant","p"],["Animal","gt"],["Lake","gf"],["Mountain","ke"]]

I need a Query that creates me the following:

Type    | Value
________________
Plant   | p
Animal  |gt
Lake    |gf
Mountain|ke

How do I do that?

0

1 Answer 1

1
SELECT e ->> 0 AS type,
       e ->> 1 AS value
FROM jsonb_array_elements(
        '[[ "Plant","p"],["Animal","gt"],["Lake","gf"],["Mountain","ke"]]'::jsonb
     ) AS e;

   type   | value 
----------+-------
 Plant    | p
 Animal   | gt
 Lake     | gf
 Mountain | ke
(4 rows)
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.