0
create table json_example as
select '[{"a":1,"b":"foo"},{"a":"2","c":"bar"}]'::jsonb as value

select * from json_example

the following is working fine:

select * from json_array_elements('[{"a":1,"b":"foo"},{"a":"2","c":"bar"}]')

And i want to do the same, only difference that json is coming from a table. how to do the same using json_example table value field?

1
  • update: i have jsonb data Commented Apr 6, 2019 at 15:02

1 Answer 1

2

cross join json_array_elements with the table

select j.* from json_example cross join
json_array_elements(value) as j

DEMO

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

12 Comments

Query execution failed Reason: SQL Error [XX000]: ERROR: failed to find conversion function from unknown to json
@clairvoyant : As I've shown in the demo, you should cast the column to json if you're using a ctas . It'll be created as unknown by default even if you've used a valid json
yes like that its work, porblem is that i have an existing table where values is a jsonb. is there something similar solution for that?
@clairvoyant : You should have told that. In that case you may use jsonb_array_elements
select j.* from json_example cross join jsonb_array_elements(value) as j . still gives me error: Reason: SQL Error [22023]: ERROR: cannot extract elements from an object
|

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.