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

260
Visualizações
Postgres operator "-" is not removing text element from jsonb array

images column is type jsonb.

Reading Postgres docs on the - operator for text it states:

Delete key/value pair or string element from left operand. Key/value pairs are matched based on their key value.

However, I am not having success. After I run my update I see the element in the array still exists. Is this because it is the only element in the array? If so, how would I deal with such a situation?

dev_dolphin_db=#  update listings set images = images - 'filename' where listings.id = 2;
UPDATE 1

id               | 2
created_at       | 2017-04-20 04:19:41.009022+00
posted_by        | 101090922
images           | [{"review": "/9j/4AAQSC1LnS//2Q==", "filename": "3/2/image-3-2-1492661981049.jpeg"}]
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If the hash is consistently in the 0th index of the jsonb array, you can delete it with

dev_dolphin_db=#  update listings set images = images #- '{0,filename}' where listings.id = 2;

This uses the #- operator which postgres describes as:

Delete the field or element with specified path (for JSON arrays, negative integers count from the end) 
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