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

205
Visualizações
Return the pre and post UPDATE column values of a specific row in PostgreSQL

I have a table with columns user_id, item_id, and test.

I'm running a query in Node.js that needs to return the value of the 'test' column for the updated row BEFORE and AFTER the update took place (in some kind of tuple format, maybe).

The query I am running is:

INSERT INTO testTable (user_id, item_id, test) VALUES($1, $2, $3) ON CONFLICT (user_id, item_id) DO UPDATE SET test = EXCLUDED.test

Essentially, I need to try to insert, unless the row with the passed in user_id/item_id pairing already exists, in which case I need to update that row with a new value for 'test'. The problem I'm having is that the 'test' column is a Boolean, and depending on if it goes from T -> F, F -> T, F -> F, or T -> T, I need it to do something different. Not sure how to handle this in the SQL statement. I was thinking a return statement but not sure how to access the before/after values of the columns.

about 4 years ago · Juan Pablo Isaza
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