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

833
Visualizações
Cadena Postgresql a jsonb_each_text()

Tengo esta cadena (caracter variable) como un valor de fila en Postgresql:

 {'img_0': 'https://random.com/xxxxxx.jpg', 'img_1': 'https://random.com/yyyyyy.jpg', 'img_2': 'https://random.com/zzzzzz.jpg'}

Estoy tratando de json_eact_text() pero no sé cómo hacerlo. He intentado to_jsonb() en él (funcionando) y luego jsonb_each(), pero tengo este error:

 ERROR: cannot call jsonb_each on a non-object

Mi consulta:

 WITH test AS ( SELECT to_jsonb(value) as value FROM attribute_value WHERE id = 43918 ) SELECT jsonb_each(value) FROM test
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Su valor de texto no es JSON válido. JSON requiere comillas dobles ( " ) para delimitar cadenas.

Esto funcionará modificando su texto siempre que sus datos sean incorrectos constantemente:

 with t (sometext) as ( values ($${'img_0': 'https://random.com/xxxxxx.jpg', 'img_1': 'https://random.com/yyyyyy.jpg', 'img_2': 'https://random.com/zzzzzz.jpg'}$$) ) select jsonb_each_text(replace(sometext, '''', '"')::jsonb) from t; jsonb_each_text --------------------------------------- (img_0,https://random.com/xxxxxx.jpg) (img_1,https://random.com/yyyyyy.jpg) (img_2,https://random.com/zzzzzz.jpg) (3 rows)

Para dividir esto en columnas:

 with t (sometext) as ( values ($${'img_0': 'https://random.com/xxxxxx.jpg', 'img_1': 'https://random.com/yyyyyy.jpg', 'img_2': 'https://random.com/zzzzzz.jpg'}$$) ) select j.* from t cross join lateral jsonb_each_text(replace(sometext, '''', '"')::jsonb) as j; key | value -------+------------------------------- img_0 | https://random.com/xxxxxx.jpg img_1 | https://random.com/yyyyyy.jpg img_2 | https://random.com/zzzzzz.jpg (3 rows)
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