Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

251
Vistas
UPDATE returning * in PostgreSQL fails

I have a query like this:

 UPDATE subscribers AS s SET status = 1 
 FROM (SELECT id FROM subscribers 
       WHERE client_id = *** AND status = 0 ORDER BY id LIMIT 5) AS t 
 WHERE t.id = s.id AND status = 0 RETURNING *

(explanation: SELECT all rows that have status=0 BUT update them to status=1 and only bring me FIVE as maximum).

I HAVE 11 rows in subscribers table with status = 0

The issue I'm having is: when I execute this query in my code (node.js, it doesn't matter what programming language, it's a query problem) in the FIRST TOW loops (first queries) it's returning 5 ROWS (that's good, as i have LIMIT 5 in the inner query).

But in the LAST QUERY I have 0 records... and in my table there's a row with status = 0 WAITING THERE TO BE FETCHED

Somebody has a clue? I'm stuck with this

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I have to say that my code was sending queries in parallel (almost at the same time), and it was creating a "race" condition, because the inner query of "subsequents" queries was receiving OLD data (before the outer UPDATE of the first query)... so this was a RACE CONDITION... i solved it after a while, thanks for your help, i'm learning a lot from this.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda