0

I've got two JSON data row from the column in postgresql database and that looks like this.

{
  "details":[{"to":"0:00:00","from":"00:00:12"}]
}

{
  "details":[ 
             {"to":"13:01:11","from":"13:00:12"}, 
             {"to":"00:00:12","from":"13:02:11"}
            ]
}

I want to iterate over details and get only the "from" key values using a query in postgresql. I want it like

                             from
                           00:00:12
                           13:00:12
                           13:02:11
2
  • The data-type of the column is jsonb or json? Commented Mar 10, 2019 at 7:00
  • yes, the datatype of a column is jsonb Commented Mar 10, 2019 at 7:02

1 Answer 1

4

Use jsonb_array_elements

select j->>'from' as "from" from t 
cross join jsonb_array_elements(s->'details') as j;

Demo

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

2 Comments

The above details are from two columns and I need to fetch all other columns like id using the key "from". from time range between 13:00:00 and 13:03:00.
@rakesh : This answers your original question, please consider asking a new one with the additional details

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.