Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

376
Views
How to extract the data from JSONB column

We have an vehicle_info stored in JSONB format in vehicle table.

id |                                     vehicle_info(JSONB)                                     
----+------------------------------------------------------------------------------------
  1 | {"milestone": {"Honda_car": {"status":"sold"}}
  3 | {"milestone": {"Mitsubishi_car", {"status":"available"}}
  2 | {"milestone": {"Honda_car", {"status":"available"}}

How do I extract the data which has suffix car.Below is the one that I could think of but ending up in an error.

select * from vehicle where milestone -> LIKE '%_car' ->>'status'
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If I followed you correctly, you can enumerate the keys with jsonb_object_keys(), then filter on those that end with '_car', and finally extract the values:

select t.*, t.vehicle_info -> 'milestone' -> k.val ->> 'status' status
from mytable t
cross join lateral jsonb_object_keys(t.vehicle_info -> 'milestone') as k(val)
where k.val like '%_car'

Demo on DB Fiddle:

id | vehicle_info                                               | status   
-: | :--------------------------------------------------------- | :--------
 1 | {"milestone": {"Honda_car": {"status": "sold"}}}           | sold     
 3 | {"milestone": {"Mitsubishi_car": {"status": "available"}}} | available
 2 | {"milestone": {"Honda_car": {"status": "available"}}}      | available
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!