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

427
Vistas
"DELETE FROM locations ORDER BY id DESC LIMIT" 1 on knex.js not working

I try write this command:

DELETE FROM locations ORDER BY id DESC LIMIT 1

on knex.js. I write this code:

knex('locations').delete().orderBy('id', 'desc').limit(1).toString()

But it return

DELETE FROM locations

Why?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Because LIMIT is not supported by Postgres and Knex is supposed to be compatible with both MySQL and PostgreSQL. See GitHub issue:

[...] this syntax isn't supported in Postgres, so that might be a bit unexpected if it's possible in one database and not another [...]

Please open a new feature request if you need this functionality to be changed.

It was mentioned there that it works since 0.6 but I can't verify that, it seems still to be not working, and that seems to be a design choice. (Personally I find this quite problematic because there is no error, you just silently get everything deleted.)

The only way to handle a DELETE LIMIT statement would be as raw query with knex.raw then.

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