0

I have a table with jsonb array column like:

 name   |  arr
---------------
 n1     [1,2,3]
 n2     [4,5,6]

I want to get a table from it like:

name   |  element
---------------
  n1        1
  n1        2
  n1        3
  n2        4
  n2        5
  n2        6

1 Answer 1

2

Use jsonb_array_elements_text

select name,j.el::int as element
   from t cross join jsonb_array_elements_text(arr) as j(el)

DEMO

Sign up to request clarification or add additional context in comments.

1 Comment

Or without a join, simply: SELECT name, jsonb_array_elements_text(arr) AS element FROM t

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.