Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

378
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda