Select in nested jsonb - postgresql

Asked

Viewed 21 times

-2

I had difficulty finding the values on a basis, as all examples cite the same way to find information in simple jsons.

But a friend from work passed me and solution and I came to share.

the initial question was: How to make a select on a nested json???

Like this:

{"vehicle":[{"vehicle_type":"Truck","car_make":"Lotus","car_model":"Esprit","quantity":7,"seats":7,"price_hour":16,"price_day":147,"color":["Purple","Pink","Blue","White"]}]}

To view the structure you can use https://jsoneditoronline.org

1 answer

0

The answer I bring uses select with regex:

select * from example
where example.jsonTest->>'vehicle' ~ 'color"\s*:\s*"?.*?Blue.*"?';

and

select * from example
where example.jsonTest->>'vehicle' ~ 'vehicle_type"\s*:\s*"?.*?SUV.*"?';

To be clear I left a functional example in https://rextester.com/BQZP48785

Browser other questions tagged

You are not signed in. Login or sign up in order to post.